在Gallery下面的RelativeLayout,Android布局无法正常显示?

时间:2012-07-13 04:25:23

标签: android layout gallery relativelayout

我有这样的布局:

<ScrollView
    android:id="@+id/ScrollViewHome"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:fillViewport="true" >

    <LinearLayout
        android:id="@+id/contentOuter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|center_horizontal" >           

        <Gallery
            android:id="@+id/home_banner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dip" >
        </Gallery>            
    </LinearLayout>
</ScrollView>

它将在屏幕中间显示我的图库。由于图像的高度不适合整个屏幕,因此在Gallery上方和下方有一个空白区域。没关系。然后我想在Gallery下面添加2个TextView:

<ScrollView
    android:id="@+id/ScrollViewHome"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:fillViewport="true" >

    <LinearLayout
        android:id="@+id/contentOuter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|center_horizontal" >           

        <Gallery
            android:id="@+id/home_banner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dip" >
        </Gallery>            

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

            <TextView
                android:id="@+id/topHotText"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:text="@string/home_segment_home1"
                android:textColor="#8e8e8e"
                android:textSize="30dp"
                android:textStyle="bold" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:text="@string/watch_all"
                android:textColor="#8e8e8e"
                android:textSize="30dp"
                android:textStyle="bold" />
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

添加<RelativeLayout>后,Gallery上方和下方的空白区域变大。 <RelativeLayout>内的2个TextView未显示。屏幕上仍然只有画廊。为什么?我写错了什么?请帮帮我。

2 个答案:

答案 0 :(得分:1)

在“滚动视图”中将“方向”垂直应用于“线性布局”。这可能是一个原因。

答案 1 :(得分:1)

将线性布局更改为垂直

 <LinearLayout
    android:id="@+id/contentOuter"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal" android:orientation="vertical">