3

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

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

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

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

附上我的布局。

<?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>
4

1 回答 1

3

我设法解决了它。我必须将内部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"
于 2012-10-16T05:57:58.360 回答