Skip to content

Commit 17d74b3

Browse files
committed
update readme
1 parent 11dfe47 commit 17d74b3

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

README_zh.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Android-ScaleLayout
2+
3+
一个简单的,方便的多屏适配的Android库
4+
5+
## 本质就是百分比缩放
6+
7+
### 和 android-percent-support-lib 的不同
8+
9+
1. **更科学**
10+
``android-percent-support-lib`` 是父控件和子控件的百分比关系
11+
``Android-ScaleLayout`` 是设计界面和设备界面的百分比关系
12+
13+
2. **更方便**
14+
``android-percent-support-lib`` 需要把设计尺寸算成百分比
15+
``Android-ScaleLayout`` 直接把设计尺寸填入``layou.xml``即可
16+
17+
18+
## How to look?
19+
20+
![screenhot](/screenhot.png)
21+
22+
23+
## 原理
24+
25+
```java
26+
float realPixel = percent * designPixel
27+
```
28+
29+
### Pix Mode
30+
31+
```java
32+
float realPixel = percent * designPixel
33+
34+
float percent = mScreenWidth / designScreenWidth
35+
36+
float designPixel = res.getDimensionPixelSize()
37+
```
38+
```java
39+
float realPixel = mScreenWidth * res.getDimensionPixelSize() / designScreenWidth
40+
```
41+
42+
### DP Mode
43+
```java
44+
float realPixel = percent * designPixel
45+
46+
float percent = mScreenWidth / designScreenWidth
47+
float designPixel = designDP * designDensity // dp to pixel
48+
49+
float designDP = res.getDimensionPixelSize() / mDensity
50+
```
51+
```java
52+
float realPixel = (mScreenWidth * designDensity * getPixelSize()) / (designScreenWidth * mDensity)
53+
```
54+
55+
## 使用
56+
57+
### 0. 依赖
58+
59+
```
60+
dependencies {
61+
compile 'cn.gavinliu.android.lib:ScaleLayout:1.0.2'
62+
}
63+
```
64+
65+
### 1. 初始化
66+
67+
```java
68+
public class MyApplication extends Application {
69+
70+
@Override
71+
public void onCreate() {
72+
ScaleConfig.create(this,
73+
1080, // Design Width
74+
1920, // Design Height
75+
3, // Design Density
76+
ScaleConfig.DIMENS_UNIT_DP);
77+
}
78+
}
79+
```
80+
81+
### 2. Scale***Layout
82+
83+
只需要把 ``FrameLayout`` ``LinearLayout`` ``RelativeLayout`` 替换成 ``ScaleFrameLayout`` ``ScaleLinearLayout`` ``ScaleRelativeLayout``.
84+
85+
### 3. Scale by width or height
86+
87+
```xml
88+
<attr name="layout_scale_by" format="enum">
89+
<enum name="width" value="0"/>
90+
<enum name="height" value="1"/>
91+
</attr>
92+
```
93+
```xml
94+
app:layout_scale_by="width"
95+
```
96+
97+
### 支持的属性
98+
99+
```xml
100+
<attr name="android:layout_width"/>
101+
<attr name="android:layout_height"/>
102+
103+
<attr name="android:layout_margin"/>
104+
<attr name="android:layout_marginLeft"/>
105+
<attr name="android:layout_marginTop"/>
106+
<attr name="android:layout_marginRight"/>
107+
<attr name="android:layout_marginBottom"/>
108+
<attr name="android:layout_marginStart"/>
109+
<attr name="android:layout_marginEnd"/>
110+
111+
<attr name="android:padding"/>
112+
<attr name="android:paddingLeft"/>
113+
<attr name="android:paddingTop"/>
114+
<attr name="android:paddingRight"/>
115+
<attr name="android:paddingBottom"/>
116+
<attr name="android:paddingStart"/>
117+
<attr name="android:paddingEnd"/>
118+
```
119+
120+
## License
121+
122+
MIT

0 commit comments

Comments
 (0)