繁体   English   中英

设备上的布局看起来有所不同

[英]Layout looks different on devices

嗨,我的应用在不同的设备上看起来有所不同。 我使用Samsung Galagy S2作为测试设备,但是当我尝试将应用程序安装到另一台设备Samsung Galaxy Note 3上时。

显示分辨率:Samsung galaxy S2:800x480(hdp)Samsung galaxz Note 3:1920x1080(xxhdp)

我的应用程序看起来:三星Galaxy S2像三星Galaxy Note 3像

如您在第一张图片中所见,它看起来不错,但是在Note 3上,应用程序底部有很多空白空间。 我使用的所有图像也是xxhdp和hdp。 问题出在按钮之间。 我在dp中进行了设置,因此我认为在每台设备中它的外观都将在手机中显示。 但是在星系S2和星系注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>

您应使用LinearLayout覆盖所有垂直按钮,并将此LinearLayout的layout_height设置为match_parent。在此LinearLayout内,将每个按钮的layout_weight设置为相同的值(例如:1),并将layout_height设置为0dp

您必须使用dimen管理高度和宽度。为values-v11,values-v14,values-sw600dp值布局创建尺寸,并根据布局和检查设置高度和宽度。

我也遇到了同样的问题,但是我通过为同一活动创建3种不同的布局来解决了这个问题。

  1. layout_large(用于xhdp布局)
  2. layout_xlarge(用于xxhdp布局)
  3. 布局(用于xhdp布局)

您无需为分配首选布局而烦恼,Android设备会选择最适合其屏幕的布局。 我的回答似乎是多余的工作,但如果您希望在不同的屏幕尺寸上获得一致的视图,则它是最可取的。 阅读文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM