i'm n开发者_运维问答ew on Android plattform. I'm trying make a View that divide the screen in three sections. The first section should be 200dip high, the third section should be 50 dip high and the middle section should take the remaining place in the middle. Is there any way to implement it? I tried some ways but either it doesn't work or the app crashed. Thanks for help Patrik
Sure. Use a RelativeLayout which looks like this.
<?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">
<!-- Defining the top view -->
<View android:layout_alignParentTop="true"
android:layout_height="200dip"
android:layout_width="fill_parent"
android:id="@+id/top_view"
android:background="#FFFF00"/>
<!-- Defining the bottom view -->
<View android:layout_alignParentBottom="true"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:id="@+id/bottom_view"
android:background="#00FFFF"/>
<!-- Defining the view in between those views -->
<View android:layout_above="@id/bottom_view"
android:layout_below="@id/top_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"/>
</RelativeLayout>
Provided comments in the code for you.
I usually achieve this by setting layout_height/width of fixed Views to specific values (e.g. android:layout_height="200dp"
) and setting android:layout_weight="1"
with android:layout_height="wrap_content"
for dynamic View. In that case LinearLayout should be used as containing ViewGroup.
精彩评论