Android布局在设备之间不一致,而不是使用dp [英] Android layout not consistent across devices instead of using dp

查看:150
本文介绍了Android布局在设备之间不一致,而不是使用dp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一张图片的屏幕截图 其他手机的屏幕截图我有一个LinearLayout,RelativeLayout,LinearLayout和一个ImageView.基本上是我的应用程序的登录页面,尽管使用dp,但在所有设备上我的输出都不相同.有两个不同手机的屏幕截图.预先感谢

Screenshot of first image Screenshot of other phoneI have a LinearLayout ,RelativeLayout,LinearLayout and a ImageView in it.This is basically a landing page of my app,inspite of using the dp my output is not same on the all device. There is the screenshot of two different phones. Thanks in advance

<LinearLayout
        android:id="@+id/lb_LinearLayout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <RelativeLayout
        android:id="@+id/lb_Relative_HomeScreen"
        android:layout_width="match_parent"
        android:layout_height="450dp">
            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="350dp">
           ``   <ImageView
                android:id="@+id/lb_Background_Image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY" />
            </LinearLayout>
            <TextView
                android:id="@+id/lb_Welcome"
                android:text="@string/welcome"
                android:gravity="start"
                style="@style/Heading2.yellow"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_gravity="start|center_vertical"
                android:layout_above="@+id/lb_Descrption"
                android:layout_marginLeft="20dp"
                />
...
</RelativeLayout>
</LinearLayout>

推荐答案

您需要为主要的屏幕密度存储区和屏幕尺寸创建不同的布局文件.这样,您将可以微调布局以在多个显示器上看起来一致.

You need to create different layout files for the major screen density buckets and screen sizes. This way you will be able to fine tune your layout to look consistent across multiple displays.

您可以从预览窗口轻松地为特定存储分区创建新的布局:

You can easily create a new layout for a specific bucket from the preview window:

  • 单击此图标.
  • 然后选择Create Other....
  • 将出现一个弹出窗口,然后从Available Qualifiers size项目中为不同密度桶的不同屏幕尺寸Density选择.
  • 选择所需项目后,按>>键,然后可以为要创建新布局文件的女巫选择合适的存储桶.
  • 此后,单击确定,然后android studio为您创建当前布局的副本并将其放置在适合您的文件夹中,您所需要做的就是对其进行编辑,以使其看起来像您想要的样子查看特定的布局.
  • Click on this icon in the left corner.
  • Then select Create Other....
  • A popup window will appear then select from the Available Qualifiers the size item for the different screen sizes of Density for the different density buckets.
  • After you selected the desired item press the >> key, and you can select the appropriate bucket for witch you wish to create a new layout file.
  • After this you press ok and the android studio creates for you a copy of the current layout and places it in the appropriate folder for you, all that you need to do is to edit it so that it look the way you want it to look on the specific layout.

这篇关于Android布局在设备之间不一致,而不是使用dp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆