【发布时间】:2014-10-30 06:13:35
【问题描述】:
嗨,我的应用在不同的设备上看起来不同。我使用 Samsung Galagy S2 作为我的测试设备,但是当我尝试将应用程序安装到另一台设备三星 Galaxy Note 3 时。
显示分辨率: 三星 Galaxy S2:800x480(hdp) 三星galaxz Note 3:1920x1080(xxhdp)
我的应用在: 三星galaxy S2赞THIS 三星galaxy Note 3赞THIS
正如您在第一张图片中看到的那样,它看起来不错,但在 Note 3 上,应用程序底部有很多空白空间。我使用的所有图像也是 xxhdp 和 hdp。问题在于按钮之间的间隙。我将它设置在 dp 中,所以我认为在每个设备中它都会像我的手机一样。但在 Galaxy S2 和 Galaxy Note 3 上,它看起来是一样的差距。
这是我的布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayoutHA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background" >
<RelativeLayout
android:id="@+id/relativeLayoutHA"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/info"
/>
<Button
android:id="@+id/facebookButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/infoButton"
android:layout_marginRight="5dp"
android:background="@drawable/facebook"
/>
<Button
android:id="@+id/emailButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:minWidth="0dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/facebookButton"
android:layout_marginRight="5dp"
android:background="@drawable/email"
/>
</RelativeLayout>
<Button
android:id="@+id/animal"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="@drawable/shape_button"
android:drawableLeft="@drawable/animal_pic"
android:text="Animals" />
<Button
android:id="@+id/insect"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_button"
android:drawableLeft="@drawable/insect"
android:text="Insects" />
<Button
android:id="@+id/nature"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_button"
android:drawableLeft="@drawable/nature"
android:text="Nature" />
<Button
android:id="@+id/people"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_button"
android:drawableLeft="@drawable/people"
android:text="People" />
<Button
android:id="@+id/gun"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="@drawable/shape_button"
android:drawableLeft="@drawable/gun"
android:text="Guns" />
</LinearLayout>
【问题讨论】:
-
两张图片相同。
-
不,我在 xxhdp 中有 260x260,在 hdp 中有 130x130
-
我是说你上传的图片是一样的。
-
发生这种情况是因为您将垂直按钮的 layout_height 固定为相同的值 (55dp)。在 xxhdpi 中,设备高度较长,因此您的应用底部有很多空白空间
-
你可以使用带有权重属性的线性布局