Skip to content

Commit

Permalink
修复部分View设置WARP_CONTENT预览显示的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Brook007 committed Feb 3, 2019
1 parent ffe496c commit 14d5e18
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_simple_px.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="50dp"
android:background="@null"
android:includeFontPadding="false"
android:text="手机验证登录"
android:textColor="#333333"
android:textSize="48px"
android:textStyle="bold"
android:gravity="center"
app:belowTo="@id/close"
app:centerInParentHorizontal="true"
app:dependency_marginTop="102px" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ public DependencyLayout(Context context, AttributeSet attrs) {
public DependencyLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display defaultDisplay = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
defaultDisplay.getMetrics(metrics);
screenWidth = metrics.widthPixels;
screenHeight = metrics.heightPixels;

this.metrics = new Metrics();

Expand Down Expand Up @@ -161,6 +155,37 @@ public DependencyLayout(Context context, AttributeSet attrs, int defStyleAttr) {
}
typedArray.recycle();
}

WindowManager wm = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
Display defaultDisplay = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
defaultDisplay.getMetrics(metrics);
if (metrics.widthPixels <= 0) {
String value = Util.getValue(mDesignWidth);
String unit = value.substring(value.length());
if ("dp".equals(unit) || "dip".equals(unit)) {
screenWidth = (int) Util.dp2px(Util.toFloat(value));
} else if ("px".equals(unit)) {
screenWidth = (int) Util.toFloat(value);
} else {
screenWidth = 1080;
}
} else {
screenWidth = metrics.widthPixels;
}
if (metrics.heightPixels <= 0) {
String value = Util.getValue(mDesignHeight);
String unit = value.substring(value.length());
if ("dp".equals(unit) || "dip".equals(unit)) {
screenHeight = (int) Util.dp2px(Util.toFloat(value));
} else if ("px".equals(unit)) {
screenHeight = (int) Util.toFloat(value);
} else {
screenHeight = 1920;
}
} else {
screenHeight = metrics.heightPixels;
}
}

@Override
Expand Down

0 comments on commit 14d5e18

Please sign in to comment.