2011-07-23 34 views
0

我有2個ScrollView,每個都包含一個TextView。第二個ScrollView通常設置爲visibility =「gone」,而ScrollView顯示全屏。Android:當包含的TextView較小時,如何調整ScrollView的大小?

當觸摸上方TextView中的腳註引用時,指定的腳註將在第二個ScrollView中正確加載和顯示,並使其可見。在這一點上,它可以滾動並且效果很好。

但是,當加載的腳註小於指定的ScrollView區域時,我希望ScrollView縮小高度以僅顯示所需的大小以顯示內容。

任何想法?基本上,我希望第二個ScrollView根據它的子TextView的內容來調整大小,直到設置的最大大小。

最終,我想讓用戶能夠通過拖動來調整腳註視圖的大小......但那是後來的事。

<?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="horizontal"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:gravity="fill" 
     android:id="@+id/contentLayout" 
     android:layout_below="@id/headerLayout"> 
     <ScrollView 
      android:id="@+id/content_scroll" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:minHeight="200dp" 
      android:fillViewport="true" 
      android:layout_below="@id/headerLayout" 
      android:layout_gravity="fill" 
      android:layout_weight="1" > 
      <TextView 
       android:id="@+id/content" 
       android:text="This is the content..." 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" /> 
     </ScrollView> 
     <ScrollView 
      android:id="@+id/note_scroll" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:visibility="gone" 
      android:background="@android:color/background_light" 
      android:layout_below="@id/content_scroll" 
      android:layout_gravity="bottom" 
      android:layout_weight="2" > 
      <TextView 
       android:id="@+id/note_content" 
       android:text="This is the note content..." 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="6dip" 
       android:paddingRight="6dip" 
       android:paddingTop="6dip"    
       android:paddingBottom="6dip"     
       android:textColor="@android:color/black" 
       android:textSize="10dp" 
       android:clickable="true" /> 
     </ScrollView> 
    </LinearLayout> 
</RelativeLayout> 

回答

0

請勿使用weight屬性。從兩個滾動視圖中移除layout_weight。

還有一件事,如果你想使用layout_weight屬性,然後設置高度0dip。它會正常工作。將這兩個屬性一起使用是沒有意義的。

謝謝

+0

嗯......當我從滾動視圖中刪除layout_weight時,腳註根本不顯示。 –

+0

它是否工作,因爲你想要或沒有。 –

+0

不,腳註似乎有零高度,現在不顯示。 –

相關問題