【问题标题】:imageview not maintaining position on all layouts in android studioimageview 未在 android studio 中的所有布局上保持位置
【发布时间】:2016-05-31 11:00:36
【问题描述】:

我的布局有问题,当我查看不同的屏幕尺寸时,我的 imageview 和 imagebutton 似乎没有保持原位!就像在 5.4 英寸 480x584 屏幕上一样,imageview 不会保持位置并朝顶部移动!我尝试的是为这个屏幕尺寸创建一个布局文件夹 sw360dp,当我查看所有屏幕时,它仍然给我其他设备屏幕上的问题!我已经阅读了开发人员文档,但仍然无法解决这个问题!,我已经包含了我的 xml 布局。谢谢

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/cropdream1">



    <ImageView
        android:src="@drawable/newbts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="82dp"
        android:id="@+id/imageView2" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/rsz_win"
        android:layout_below="@+id/imageView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="104dp" />

</RelativeLayout>

【问题讨论】:

  • 请查看this answer
  • 感谢您的回复,但不是我想要的,我已经从您提供的链接中获得了这些布局,但不推荐使用 layout-large 等,因此平板电脑应为 sw600dp,小型手机等应为 sw360dp等等,我遇到的问题是图像视图和图像按钮在选择不同的屏幕预览时在设计器布局中移动

标签: xml android-studio android-imageview android-xml


【解决方案1】:

在测试了许多不同的布局选项后,我发现我哪里出错了! 我放在第一个主要 relativeLayout 中的背景图像不应该在那里,并且在不同的屏幕上测试时,imageview 没有用这个调整! 我解决这个问题的方法是放置一个子 RelativeLayout 并在此处设置可绘制的背景!然后我将 imagview 和 imagebutton 放置在此布局中,现在可以正确缩放! 我希望这个答案对其他人有所帮助。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/cropdream1">


    <ImageView
        android:src="@drawable/newbts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="82dp"
        android:id="@+id/imageView2" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/rsz_win"
        android:layout_below="@+id/imageView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="104dp" />

</RelativeLayout>

</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    相关资源
    最近更新 更多