RelativeLayout问题 - 图像重叠ScrollView

时间:2011-09-16 09:50:05

标签: android relativelayout

我阅读了已发布的所有相关布局问题,我想我会注意双重询问,对不起,如果我是。

我正试图在我的应用程序底部粘贴一个图像,上面是我有一个滚动视图,如下所示:

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/RelativeLayout1">
        <ScrollView  android:paddingTop="180dip" android:layout_width="fill_parent" android:id="@+id/scrollView12" android:layout_height="wrap_content">
            <LinearLayout android:id="@+id/linearLayout4" android:layout_width="fill_parent" android:paddingRight="8dip" android:orientation="vertical" android:layout_height="wrap_content">
            </LinearLayout>
        </ScrollView>
        <ImageView android:layout_width="fill_parent"
            android:background="@color/cinza" android:src="@drawable/header"
            android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_alignParentBottom="true">
        </ImageView>
</RelativeLayout>

我以动态方式提供了滚动视图,因此它的大小可以改变。我的问题是,如果它一直长到显示结束,最后的记录就会落后于我的照片。我想让它成长直到画面。 有关如何做到这一点的一些线索?我尝试了几种方法,相对布局,线性布局,但有时画面消失,有时候不会粘在底部...... 希望我的问题很明确。

提前致谢,

João

3 个答案:

答案 0 :(得分:4)

您应该为ScrollView添加android:layout_above="@+id/imageView2",然后首先定义ImageView,然后首先定义,然后在RelativeLayout内部使用ScrollView。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/RelativeLayout1">
    <ImageView
        android:layout_width="fill_parent"
        android:background="@color/cinza"
        android:src="@drawable/header"
        android:id="@+id/imageView2"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
    </ImageView>
    <ScrollView
        android:paddingTop="180dip"
        android:layout_width="fill_parent"
        android:id="@+id/scrollView12"
        android:layout_above="@+id/imageView2"
        android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_width="fill_parent"
            android:paddingRight="8dip"
            android:orientation="vertical"
            android:layout_height="wrap_content">
        </LinearLayout>
    </ScrollView>   
</RelativeLayout>

答案 1 :(得分:1)

在这种情况下,

RelativeLayout不是正确的选择。您必须使用LinearLayout,密钥是android:layout_weight参数:

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

    <ScrollView  android:paddingTop="180dip" 
        android:layout_width="fill_parent" 
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout android:id="@+id/linearLayout4" 
            android:layout_width="fill_parent" 
            android:paddingRight="8dip" 
            android:orientation="vertical" 
            android:layout_height="wrap_content">
        </LinearLayout>
    </ScrollView>

<ImageView android:layout_width="fill_parent"
    android:background="@color/cinza" 
    android:src="@drawable/header"
    android:id="@+id/imageView2" 
    android:layout_height="wrap_content" />

答案 2 :(得分:0)

为scroolview提供id然后在图像视图中设置标记android:layout_blow =“id of scrollview”

我希望这是答案。