imageview 未在 android studio 的所有布局上保持位置
imageview not maintaining position on all layouts in android studio
我的布局有问题,当我查看不同的屏幕尺寸时,我的 imageview 和 imagebutton 似乎不在原位!就像在 5.4 英寸 480x584 屏幕上一样,图像视图不会保持位置并向顶部移动!我尝试的是为此屏幕尺寸创建一个布局文件夹 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>
在测试了许多不同的布局选项后,我发现我哪里出错了!
我放置在第一个主要 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>
我的布局有问题,当我查看不同的屏幕尺寸时,我的 imageview 和 imagebutton 似乎不在原位!就像在 5.4 英寸 480x584 屏幕上一样,图像视图不会保持位置并向顶部移动!我尝试的是为此屏幕尺寸创建一个布局文件夹 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>
在测试了许多不同的布局选项后,我发现我哪里出错了! 我放置在第一个主要 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>