【问题标题】:Layout repeats on device but looks fine on emulator when adding image in a Relative Layout布局在设备上重复,但在相对布局中添加图像时在模拟器上看起来不错
【发布时间】:2012-10-16 03:57:46
【问题描述】:

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

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

但是当我将图像放在标题图像下方时,布局会在设备中重复。这意味着我可以在设备中看到 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>

【问题讨论】:

  • 有一个标签没有匹配的标签,是这个问题吗?
  • 如果 只是一个错字,然后尝试将属性 android:layout_below="@id/header" 添加到 'content' 布局中,可以强制下面的内容标题。
  • @ZitengChen adt 捕获此类错误,如果 &lt;/ScrollView&gt; 不是拼写错误,则不应编译。
  • @ZitengChen 抱歉,我在这里粘贴代码时忘记删除它们。不,这不是问题。以前我有一个滚动视图,我把它放在标题下方。但我仍然遇到同样的问题。我认为删除滚动视图会有所帮助,但它是一样的。
  • 好的,如果你想把内容放在标题下面,那么你应该在内容布局中添加属性 android:layout_below="@id/header",否则内容将默认对齐顶部父布局的边框并与标题重叠。

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


【解决方案1】:

我设法解决了。 我必须将内部 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"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 2021-07-30
    • 1970-01-01
    • 2020-04-26
    相关资源
    最近更新 更多