[英]android layout vertical/horizontal weight
我为每个设备的不同分辨率使用Android的LinearLayout
。 这样我可以解决不同分辨率的垂直布局问题。
但是我不能解决水平布局问题。 他是我的布局。 我想要这样的布局。
在这种情况下,我使用左/右页边距,但这不适用于其他分辨率。 如何将TextView
与分辨率相关?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<TextView
android:id="@+id/titleView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="9"
android:gravity="center"
android:text="TextView"
android:textColor="#5a5856"
android:textSize="35sp" />
<TextView
android:id="@+id/wordDafinitionView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:textSize="17sp"
android:layout_marginLeft="25dp"
android:layout_marginRight="30dp"
android:text="TextView"
android:textColor="#5a5856" />
<TextView
android:id="@+id/TextView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="9"
android:gravity="center"
android:text="TextView"
android:textColor="#5a5856"
android:textSize="35sp" />
</LinearLayout>
一种解决方案是您可以使用
DisplayMetrics metrics = getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
并检查不同的设备屏幕尺寸,
if((metrics.heightPixels/metrics.density) >= 700)
{
Log.e(" 10 inch Tab", " 10 inch Tab");
}
else if((metrics.heightPixels/metrics.density) >= 550)
{
Log.e(" 7 inch Tab", " 7 inch Tab");
}
else if((metrics.heightPixels/metrics.density) >= 400)
{
Log.e(" 5 inch Tab / Mobile", " 5 inch Tab / Mobile");
}
else
{
Log.e("All other mobile devices", "All mobile other devices");
}
然后相应地设置TextView的宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.