android - 布局在设备上重复,但在相对布局中添加图像时在模拟器上看起来不错

标签 android android-layout android-imageview android-image

让我试着用我想要的在这里解释清楚。我有一个 RelativeLayout,其中包含标题图像及其下方的内容。

现在,当我有一个标题图像和一个 ListView 在它下面时,页面正确地适合设备的屏幕,布局不会重复。

但是当我将图像放在标题图像下方时,布局会在设备中重复。这意味着我可以在设备中看到 2 个标题图像。某些页面,我可以看到不应该存在的一半标题图片(重复的标题图片)。但是,在模拟器中,所有页面看起来都很好并且很适合屏幕。

我尝试更改为 LinearLayout,LinearLayout 内的 RelativeLayout,RelativeLayout,它给了我相同的结果。我希望有人能告诉我为什么会这样。 谢谢。

附件是我的布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/bg" >

<ImageView
android:id="@+id/header"
android:contentDescription="@string/image"
android:src= "@drawable/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"/>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >

<ImageView
android:id="@+id/journal"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignTop="@+id/kick"
android:adjustViewBounds="true"
android:contentDescription="@string/image"
android:padding="10dp"
android:src="@drawable/favourite_journal" />

<ImageView
android:id="@+id/kick"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_toRightOf="@+id/journal"
android:layout_below="@+id/header"
android:adjustViewBounds="true"
android:contentDescription="@string/image"
android:padding="10dp"
android:src="@drawable/favourite_kick" />

<ImageView
android:id="@+id/labour"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@+id/journal"
android:layout_alignLeft="@+id/journal"
android:adjustViewBounds="true"
android:contentDescription="@string/image"
android:padding="10dp"
android:src="@drawable/favourite_labour" />

<ImageView
android:id="@+id/share"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@+id/kick"
android:layout_alignLeft="@+id/kick"
android:adjustViewBounds="true"
android:contentDescription="@string/image"
android:padding="10dp"
android:src="@drawable/favourite_share" />
</RelativeLayout>
</RelativeLayout>

最佳答案

我设法解决了它。 我必须将内部 RelativeLayout 的 layout_width 和 layout_height 设置为 fill_parent。

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header"    
android:orientation="vertical">

感谢@Ziteng Chen 暗示我的立场。

android:layout_below="@+id/header"  

还有@BobbiHoddi 提出了删除 adjustViewBounds 的建议。它帮助解决了我在图像中遇到的其他错误。

android:adjustViewBounds="true"

关于android - 布局在设备上重复,但在相对布局中添加图像时在模拟器上看起来不错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12907345/

相关文章:

java - 选择 View 中的所有复选框

android - 如何使用 Android Espresso 测试 TextInputLayout 值(提示、错误等)?

java - TabLayout 图标大小未正确缩放

不同选项卡中的android fragment

java - 分页库最初返回空列表

java - 使用 onActivityResult 调用函数

android - 如何编写 Android 4.0 样式部分

java - 如何在圆形 ImageView 中添加图标

android - 比屏幕大的ImageView作为背景

android:耳机插头监听器