2016-05-13 88 views
0

我有一个LinearLayout与3个孩子权重设置其比例:1/7,3/7,3/7。最后一节包含的文本可能会超出允许的空间,所以我添加了一个滚动视图。ScrollView填充屏幕时,子视图太大

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" 
     android:orientation="vertical" 
     android:background="@drawable/package_status_border"/> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3"> 

     <TextView 
      android:id="@+id/PackageContent" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 

    </ScrollView> 

</LinearLayout> 

这种布局是工作的罚款,如果PackageContent文字太小: expected formatting

但是,如果PackageContent文本是大的,而不是保持期望的高度,只是滚动它填补了多余的文字整个屏幕: bad formatting, with scroll view filling entire screen

如何确保最后一部分仍然只有3/7的屏幕,与内容滚动,无论textView包含多少内容?

我也试过把ScrollView放在它自己的LinearLayout中,但是也没有工作。

回答

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" 
     android:orientation="vertical" 
     android:background="@drawable/package_status_border"/> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3"> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:id="@+id/PackageContent" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"/> 

     </ScrollView> 

    </FrameLayout> 

</LinearLayout> 
+0

不,同样的问题,使用FrameLayout – user2957533