Skip to content

Commit fc02f1d

Browse files
author
hongyangAndroid
committed
fix preview的问题,由check design size 导致
1 parent c6cfc31 commit fc02f1d

File tree

7 files changed

+30
-5
lines changed

7 files changed

+30
-5
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ dependencies {
5555

5656
```
5757
dependencies {
58-
compile 'com.zhy:autolayout:1.3.3'
58+
compile 'com.zhy:autolayout:1.3.4'
5959
}
6060
```
6161

@@ -104,6 +104,27 @@ dependencies {
104104
* textSize
105105

106106

107+
## 预览
108+
109+
大家都知道,写布局文件的时候,不能实时的去预览效果,那么体验真的是非常的不好,也在很大程度上降低开发效率,所以下面教大家如何用好,用对PreView(针对该库)。
110+
111+
首先,你要记得你设计稿的尺寸,比如 `768 * 1280`
112+
113+
然后在你的PreView面板,选择于设计图分辨率一致的设备:
114+
115+
116+
<img src="autolayout_07.png" width="480px"/>
117+
118+
然后你就可以看到`最为精确的`预览了:
119+
120+
<img src="autolayout_06.png" width="480px"/>
121+
122+
两个注意事项:
123+
124+
1. 你们UI给的设计图的尺寸并非是主流的设计图,该尺寸没找到,你可以自己去新建一个设备。
125+
2. 不要在PreView中去查看所有分辨率下的显示,是看不出来适配效果的,因为有些计算是动态的。
126+
127+
107128
## 注意事项
108129

109130
### ListView、RecyclerView类的Item的适配

autolayout/autolayout.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":autolayout" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.zhy" external.system.module.version="1.3.2" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":autolayout" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.zhy" external.system.module.version="1.3.3" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>

autolayout/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33
apply plugin: 'com.jfrog.bintray'
44

5-
version = "1.3.3"
5+
version = "1.3.4"
66

77
android {
88
compileSdkVersion 23

autolayout/src/main/java/com/zhy/autolayout/AutoFrameLayout.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.view.ViewGroup;
2222
import android.widget.FrameLayout;
2323

24+
import com.zhy.autolayout.config.AutoLayoutConifg;
2425
import com.zhy.autolayout.utils.AutoLayoutHelper;
2526

2627
public class AutoFrameLayout extends FrameLayout
@@ -52,7 +53,9 @@ public LayoutParams generateLayoutParams(AttributeSet attrs)
5253
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
5354
{
5455
if (!isInEditMode())
56+
{
5557
mHelper.adjustChildren();
58+
}
5659
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
5760
}
5861

@@ -70,6 +73,7 @@ public static class LayoutParams extends FrameLayout.LayoutParams
7073
public LayoutParams(Context c, AttributeSet attrs)
7174
{
7275
super(c, attrs);
76+
7377
mAutoLayoutInfo = AutoLayoutHelper.getAutoLayoutInfo(c, attrs);
7478
}
7579

autolayout/src/main/java/com/zhy/autolayout/utils/AutoLayoutHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ private void initAutoLayoutConfig(ViewGroup host)
100100

101101
public void adjustChildren()
102102
{
103+
AutoLayoutConifg.getInstance().checkParams();
104+
103105
for (int i = 0, n = mHost.getChildCount(); i < n; i++)
104106
{
105107
View view = mHost.getChildAt(i);
@@ -122,8 +124,6 @@ public static AutoLayoutInfo getAutoLayoutInfo(Context context,
122124
AttributeSet attrs)
123125
{
124126

125-
AutoLayoutConifg.getInstance().checkParams();
126-
127127
AutoLayoutInfo info = new AutoLayoutInfo();
128128

129129
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoLayout_Layout);

autolayout_06.png

305 KB
Loading

autolayout_07.png

241 KB
Loading

0 commit comments

Comments
 (0)