我为android设计。我有几部手机。他们有不同的决议。我有一个解决1440X2560 px的设计。屏幕有3个不同宽度的正方形。宽度为1440像素,xxxhdpi = 360 dpi。我有每个布局的宽度。现在如果我在三星Galaxy Note 4(1440x2560 640 dpi)上运行应用程序,一切看起来都应该如此。现在,如果我在Nexus 6(1440x2560?dpi)上运行该应用程序,则图片不是整个屏幕。我发现nexus 6的分辨率在xxhdpi和xxxhdpi之间。问题是我如何标记屏幕,使其在所有手机上看起来都一样?或者我不应该使用dpi?enter link description here
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="60dp"
android:layout_height="100dp"
android:background="#ffff2622">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="200dp"
android:layout_height="100dp"
android:background="#ff42ff20">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#ff4934ff">
</LinearLayout>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:1)
根据this,Nexus 6确实介于xxhdpi
和xxxhdpi
之间,规模约为3.5。我不是@Squonk建议的布局权重的粉丝所以我建议使用dimensions。
为不同的屏幕宽度创建值文件夹,例如values-w320dp
,values-w360dp
,values-w410dp
等。您可以为不同的屏幕宽度定义尺寸。
<resources>
<dimen name="left_column">60dp</dimen>
<dimen name="middle_column">200dp</dimen>
<dimen name="right_column">100dp</dimen>
</resources>
在您的xml中,您可以引用layout_width="@dimen/left_column"
我还建议只设置左右列宽,并让中间一个填充剩余空间。你可以用RelativeLayout
。
答案 1 :(得分:0)
在我看来,你想要创造你的方块&#39;比例为60:200:100(也是3:10:5)。请尝试以下方法,按layout_weight
...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="3"
android:background="#ffff2622">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="10"
android:background="#ff42ff20">
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="5"
android:background="#ff4934ff">
</LinearLayout>
</LinearLayout>
</LinearLayout>
使用android:layout_width=0dp
和android:layout_weight=
会根据所有权重值之和的百分比为每个元素提供一个大小。