开发者

Android: How do I resize a ScrollView smaller when the contained TextView is smaller?

I have 2 ScrollView's, each containing a TextView. The second ScrollView is set visibility="gone" normally, and the ScrollView displays full screen.

When a footnote reference in the upper TextView is touched, the specified footnote is loaded and displayed correctly in the second ScrollView and it's made visible. At this point, it's scrollable and works great.

But, when the loaded footnote is smaller then the specified ScrollView area, I would like the ScrollView to shrink in height to only the necessary size to display the content.

Any ideas? Basically, I want the second ScrollView to resize based on it's child TextView's content, up to a set maximum size.

Eventually, I want to allow the user to be able to resize the footnote view by dragging...but that is later.

<?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" 
                andr开发者_如何学JAVAoid: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>


Do not use weight attribute. Remove layout_weight from both the scroll views.

or

and one more thing if you want to use layout_weight attribute, then set height to 0dip. It will work fine. There is no sense in using both of these attributes together.

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜