How to use Scroll View In Android

前端 未结 2 627
盖世英雄少女心
盖世英雄少女心 2020-12-22 14:04

I have use two scroll views for two different layout. And those two layouts are inside a Linear Layout.

Here is my XML file. I don\'t why ScrollView is

相关标签:
2条回答
  • 2020-12-22 14:34

    if you are display your scrollview in Horizontal Linear Layout and given a weight to scrollview then set width of Scrollview to "0dp"

    android:layout_width="0dp"
    

    and if it is vertical then

    android:layout_height="0dp"
    

    also set your main LinearLayout height to fill parent

    0 讨论(0)
  • 2020-12-22 14:50

    I think you need a simple, two-column organization:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        <!-- stuff goes here that should appear above the scrolling areas -->
    
        <ScrollView
            android:id="@+id/left_side_scroller"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
    
            <!-- contents of left side go here -->
        </ScrollView>
    
        <ScrollView
            android:id="@+id/right_side_scroller"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
    
            <!-- contents of right side go here -->
        </ScrollView>
    
        <!-- stuff goes here that should appear below  the scrolling areas -->
    </LinearLayout>
    

    Alternatively (and perhaps better) it looks like you should be using two ListView elements instead of two ScrollView elements. Each ListView would have the same layout parameters as shown above for the ScrollView. Since a ListView manages scrolling internally, you then don't need ScrollView at all.

    Also, you probably want the entire layout to fill the screen, with the "filter" and "sort" elements always at the bottom. To achieve this effect,the top-level layout should have android:layout_height="fill_parent" instead of "wrap_content". Also, the scrollable areas should have android:layout_height="0dp" and a non-zero weight (which they already do).

    0 讨论(0)
提交回复
热议问题