在我的应用程序屏幕中,有两个列表视图说L1(填充数据D1)和L2(填充数据D2)和屏幕底部的一个按钮。
显示列表的条件:
if(show D1){
//Display L1 list in the middle of screen and button at the bottom of screen.
//Hide L2
}
if(show D2){
//Display L2 list in the middle of screen and button at the bottom of screen.
//Hide L1
}
if(show D1 && D2){
if(D1>=D2){
//Display L1 and L2 lists in the middle of screen and
//button at the bottom of screen.
}else if(D1<D2){
//Display L1 and L2 lists in the middle of screen and
//button at the bottom of screen.
}
}
通过使用以下布局,它可以在一次显示两个列表时正确显示所有内容。但是当显示L1时,它覆盖整个屏幕并重叠按钮,当显示L2时,当数据很少时它会正确显示但按钮在列表下方而不是屏幕底部向上。 layout.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background_main"
>
<LinearLayout
android:id="@+id/layout1"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtSubHeadingW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:layout_marginTop="2dp"
android:paddingLeft="18dp"
android:gravity="center"
android:maxLines="1"
android:text="@string/lbl1"
android:textColor="@color/BlueViolet"
android:textStyle="bold" style="@style/style_text"
/>
<ListView
android:id="@+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:cacheColorHint="#00000000"
/>
</LinearLayout>
<LinearLayout android:id="@+id/layout2"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txtSubHeadingT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="18dp"
android:gravity="center"
android:maxLines="1"
android:text="@string/lbl2"
android:textColor="@color/BlueViolet"
android:textStyle="bold"
android:visibility="gone" style="@style/style_text"
/>
<ListView
android:id="@+id/l2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:cacheColorHint="#00000000"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/lnrControls"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dip"
android:background="@drawable/top_portrait"
android:gravity="center"
android:orientation="horizontal"
android:padding="3dip"
>
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_text_selector"
android:text="@string/lbl_ok"
android:gravity="center"
android:textColor="@color/White"
android:layout_gravity="center" style="@style/style_text"
/>
</LinearLayout>
</LinearLayout>