Android相对布局使用dp跳遍

标签 android android-layout android-relativelayout

我已尝试尽可能准确地匹配为此设计的平板电脑,Samsung Tab S2 - 9.7"屏幕尺寸,2048x1536 - 我创建了一个 AVD 来匹配它。

我已将图像排列如下所示:

enter image description here

但是当我部署它时,它们跳来跳去,如下所示:

enter image description here

根据其他平板电脑,它们会变得更糟,但我现在只是尝试一个。我在尺寸和边距上使用带 DP 的全屏相对布局,那么为什么它们跳来跳去这么多?它不应该总是与顶部/侧面的距离相同吗?为什么即使尺寸和像素在 AVD 和平板电脑中完全匹配,它也会四处移动?

我完全迷路了,我已经阅读了从代码中设置边距到绝对布局(不再支持)的所有内容。一切都指向 DP,但即使使用完全匹配的平板电脑和设计器,它们也会改变位置和大小。

<FrameLayout 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:background="@drawable/background_buttons"
tools:context="com.cimulus.samocoseat.MainMenu">

<!-- This FrameLayout insets its children based on system windows using
     android:fitsSystemWindows. -->
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fullscreen_content_controls_a"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:ignore="UselessParent">
        <ImageView
            android:id="@+id/seatView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/seat"
            android:layout_marginTop="60dp"
            android:layout_marginBottom="60dp"
            android:layout_marginLeft="245dp"
            />

        <ImageButton
            android:layout_width="124dp"
            android:layout_height="75dp"
            android:text="Seat Back Forward"
            android:id="@+id/seatBackForward"
            android:background="@drawable/left_inactive"
            android:layout_marginTop="266dp"
            android:layout_marginStart="38dp" />

        <Button
            android:layout_width="124dp"
            android:layout_height="75dp"
            android:text="Seat Back Forward"
            android:id="@+id/legRightExtension"
            android:background="@drawable/left_inactive"
            android:layout_marginTop="142dp"
            android:layout_marginLeft="100dp" />

    </RelativeLayout>
</FrameLayout>

非常感谢任何帮助。

编辑:我也尝试过它自己存在的相对布局,总体上给了我相同的结果:

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fullscreen_content_controls_a"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/background_buttons">
        <ImageView
            android:id="@+id/seatView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/seat"
            android:layout_marginTop="60dp"
            android:layout_marginBottom="60dp"
            android:layout_marginLeft="245dp"
            />

        <ImageButton
            android:layout_width="124dp"
            android:layout_height="75dp"
            android:text="Seat Back Forward"
            android:id="@+id/seatBackForward"
            android:background="@drawable/left_inactive"
            android:layout_marginTop="266dp"
            android:layout_marginStart="38dp" />

        <Button
            android:layout_width="124dp"
            android:layout_height="75dp"
            android:text="Seat Back Forward"
            android:id="@+id/legRightExtension"
            android:background="@drawable/left_inactive"
            android:layout_marginTop="142dp"
            android:layout_marginLeft="100dp" />

    </RelativeLayout>

最佳答案

我遇到了类似的问题,有人建议使用这个库 - https://github.com/intuit/sdp .它提供了在具有不同屏幕特征的设备之间自动缩放的单位。希望对您有所帮助:)

关于Android相对布局使用dp跳遍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38613690/

相关文章:

android - 提高json解析性能

android - 如何保持自动完成 TextView 为空(准备好输入)?

android - 如何将文本放在 CollapsingToolbarLayout 和 Toolbar 的中心?

android - textIsSelectable 不适用于 descendantFocusability=blocksDescendants

android - ScrollView 下方的对象未显示

android - 如何在 Android 应用程序中启用 TLS 1.2 支持(在 Android 4.1 JB 上运行)

java - Android升级应用程序版本时资源会发生什么变化

Android - 在 Lollipop 之前的设备上为 ProgressBar 着色

android - "Must supply height attribute"错误

java - Android的RelativeLayout动画问题