【问题标题】:Layout displayed differently on different devices at the same resolution screen同一分辨率屏幕下不同设备显示的布局不同
【发布时间】:2015-05-30 12:41:09
【问题描述】:

问题:布局在不同设备上相同分辨率屏幕上显示不同。我在 Samsung Galaxy S4 (1080x1920) 和 LG G2 (1080x1920) 上对其进行了测试。分辨率一样,为什么每个设备的布局显示不一样?

我全部都在布局文件夹中,没有其他分辨率的其他布局。

这里是屏幕:

  • 三星 Galaxy S4

http://www.image-share.com/ijpg-2963-272.html

  • LG G2

http://www.image-share.com/ijpg-2963-271.html

编辑#1

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layoutMain"
tools:mContext="com.test.app.flock.mActivity">

<ImageView
    android:id="@+id/imageViewImageBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone" />

<View
    android:id="@+id/viewBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background01" />

<View
    android:id="@+id/viewFingerprint"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/fingerprint01"
    android:visibility="gone" />

<Button
    android:id="@+id/buttonScanning"
    android:layout_width="162dp"
    android:layout_height="130dp"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="41dp"
    android:background="@android:color/transparent" />

<ImageView
    android:id="@+id/imageViewScanner"
    android:layout_width="162dp"
    android:layout_height="130dp"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="41dp"
    android:src="@drawable/line01"

    android:visibility="gone" />

<TextView
    android:id="@+id/textViewResult"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="180dp"

    android:text="SCANNING"
    android:textSize="30sp"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    android:gravity="center"

    android:visibility="gone" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="112dp"
    android:orientation="vertical">

    <DigitalClock
        android:id="@+id/digitalClock"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="7"

        android:textSize="30sp"
        android:textColor="@android:color/white"
        android:gravity="center"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textViewDate"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="10"

        android:text="10 Grudzien 2015"
        android:textSize="20sp"
        android:textColor="@android:color/white"
        android:gravity="center"
        android:textStyle="bold" />

</LinearLayout>

【问题讨论】:

  • 这与像素的密度有关。但是您应该没有问题,因为您使用 XML 作为 UI 并且您在 DP(密度像素)中给出宽度和高度。
  • 布局仅在 S4 上以不同的方式显示。在具有相同屏幕分辨率的其他设备上,一切都很好。那么问题出在哪里?
  • 这个问题你解决了吗?我有同样的问题:new.izigo.pt/content/images/IMG_3209.JPG
  • @Patrick,Android 为每个设备报告的screen density 是什么?
  • @Onik 嗨,谢谢!我可以直接从设备界面获取这些信息吗?联想 (gsmarena.com/lenovo_tab3_7-7951.php) 网站说:“600 x 1024 像素,16:9 比例(~170 ppi 密度)”和华为(gsmarena.com/huawei_mediapad_t3_7_0-8635.php)说:“600 x 1024 像素,16:9 比例(~170 ppi 密度) )”。我只发现了区别:7.0 英寸,137.9 cm2(~72.2% 的屏占比)和 7.0 英寸,137.9 cm2(~74.3% 的屏占比)

标签: android android-layout screen-resolution screen-density


【解决方案1】:

这两款手机的分辨率相同,但窗口高度不同,因为 LG G2 的屏幕上有导航键。

【讨论】:

  • 嗯,是的。那么我该如何解决呢?如何创建单独的布局?
  • 与其尝试绝对定位视图以使其似乎拥有自己的背景,不如为整个屏幕制作一个背景,为每个视图制作一个背景
  • 也许是一种为带导航栏和不带导航栏的设备执行两个 xml 文件的方法?
  • 是的,但你不会只以两个 xml 结束。基本上你需要一个 xml 每个设备 100% 确保它看起来正确
  • 我也有同样的问题,但导航键不可见:new.izigo.pt/content/images/IMG_3209.JPG 任何想法我该如何解决?
【解决方案2】:

问题不在于布局或密度,而在于可用的不同高度,因为存在按钮栏。 由于设置为Viewbackground 的图像会膨胀,扭曲自身,我建议您将其设置为ImageViewsrc,并将scaleType 设置为fitCenter,这样图像就会适合屏幕并保持其比例:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitCenter"
    android:src="@drawable/background01" />

【讨论】:

  • 您好,谢谢!在我的情况下,它是一个带有 loadUrl 的 webView,所以我无法访问图像,它在 HTML 中。
猜你喜欢
  • 1970-01-01
  • 2014-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-06
  • 1970-01-01
  • 2017-03-24
相关资源
最近更新 更多