【问题标题】:fill_parent doesn't work for RelativeLayout in ScrollViewfill_parent 不适用于 ScrollView 中的 RelativeLayout
【发布时间】:2014-10-06 23:39:47
【问题描述】:

我在设置为fill_parent 的ScrollView 中有一个RelativeLayout。但是,它仅水平填充,而不是垂直填充。还有更多内容我想放在RelativeLayout中,但首先我需要弄清楚为什么RelativeLayout不会填满ScrollView的高度。

感谢您的帮助。

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/gray"
    android:layout_below="@+id/previewButton"
    android:layout_marginTop="10dp" >

    <RelativeLayout
        android:id="@+id/relativeLayout"
        android:layout_below="@+id/matchingWordsLabel"
        android:background="@color/white"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        >

        <TextView
            android:id="@+id/titleLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="Title:"
            />

            <EditText
            android:id="@+id/title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/titleLabel"
            android:layout_alignBaseline="@+id/titleLabel"
            android:ems="10" />
    </RelativeLayout>
</ScrollView>

【问题讨论】:

    标签: android android-layout android-relativelayout


    【解决方案1】:

    添加

    android:fillViewPort="true"
    

    ScrollView

    fill_parentmatch_parentScrollView 中的高度实际上没有意义,它会被忽略——否则就不需要滚动了。 fillViewPort="true" 使滚动视图占据屏幕上所有可用的垂直空间。

    【讨论】:

      【解决方案2】:

      因为 ScrollView 只能有一个孩子在其中放置一个 LinearLayout。在 LinearLayout 中放置 RelativeLayout。将高度设置为 wrap_content。

      <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/svRecord"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center_horizontal"
      android:orientation="vertical" >
      
      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="left"
          android:orientation="vertical"
          android:paddingLeft="12dp"
          android:paddingRight="12dp"
          android:visibility="visible" >
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-26
        • 1970-01-01
        • 1970-01-01
        • 2012-06-06
        • 1970-01-01
        • 1970-01-01
        • 2013-12-16
        • 1970-01-01
        相关资源
        最近更新 更多