我是为android设计的。我有几部手机。他们有不同的分辨率。我有一个1440x2560px分辨率的设计。屏幕有3个不同宽度的方块。xxxhdpi =360dpi1440像素的宽度。我有每个布局的宽度。现在,如果我在Samsung Galaxy Note4 (1440x2560 640dpi)上运行这个应用程序,一切看起来都是正常的。现在,如果我在Nexus 6上运行该应用程序(1440x2560?dpi)图片并不是整个屏幕。我发现nexus6的分辨率介于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>发布于 2015-03-20 17:00:56
根据this的说法,Nexus6实际上介于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来做到这一点。
发布于 2015-03-20 12:24:52
在我看来,你想创建一个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=将根据所有权重值之和的百分比为每个元素指定大小。
https://stackoverflow.com/questions/29159206
复制相似问题