ANDROID : split the screen in 2 equals parts with 2 listviews

后端 未结 3 1516
再見小時候
再見小時候 2020-11-30 05:27

I\'m trying to put 2 listviews into my layout. The problem is that I don\'t know the size of each listview in advance. The first listview could have a few items (0, 1, 2 up

相关标签:
3条回答
  • 2020-11-30 05:32

    Try to set sizes in soft pixels (device independent ones) - like "50sp" or "100sp" - I'm sure you'll find appropriate one

    0 讨论(0)
  • 2020-11-30 05:44

    I simply had to "encapsulate" my 2 listviews into 2 separate linearlayouts => these 2 linearlayout have a weight of 1 :

        <LinearLayout android:layout_weight="1" 
                        android:layout_height="fill_parent" 
                        android:layout_width="fill_parent">
    
                    <ListView   android:id="@+id/ListView_NASDAQ100" 
                                android:layout_height="fill_parent" 
                                android:layout_width="fill_parent">
    
                    </ListView>
        </LinearLayout>
    
    <LinearLayout android:layout_weight="1" 
                    android:layout_height="fill_parent" 
                    android:layout_width="fill_parent">
    
                <ListView   android:id="@+id/ListView_from_52w_HIGHLOW" 
                            android:layout_height="fill_parent" 
                            android:layout_width="fill_parent">
    
                </ListView>
    </LinearLayout>
    
    0 讨论(0)
  • 2020-11-30 05:56
    <LinearLayout
            android:id="@+id/ListView_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="1" >
    
            <RelativeLayout
                android:id="@+id/rl_ListView1"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5" >
    
                <ListView
                    android:id="@+id/lv1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                    </ListView>
            </RelativeLayout>
    
            <RelativeLayout
                android:id="@+id/rl_ListView2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.5" >
    
                <ListView
                    android:id="@+id/lv2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </ListView>
    
            </RelativeLayout>
        </LinearLayout>
    

    Create a parent Linear Layout, define a weightsum and split that into two different relative layouts each of weight equals half of total weightsum because in relative layout things are managed easily and properly .I hope this works for you

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