Android 布局----让一个控件居底部

1.采用linearlayout布局

Java code
<LinearLayout android:id="@+id/main"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical">

<LinearLayoutandroid:id="@+id/content"

android:layout_width="fill_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:orientation="vertical"/>

<LinearLayoutandroid:id="@+id/bottom_panel"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<Buttonandroid:id="@+id/done"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:layout_gravity="center_vertical"

android:text="done"/>

<Buttonandroid:id="@+id/revert"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:layout_gravity="center_vertical"

android:text="revert"/>

</LinearLayout>

</LinearLayout>

2. 采用relativelayout布局:

Java code
<RelativeLayout android:id="@+id/main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >
    
    <LinearLayout android:id="@+id/content" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" /> 
        
        <LinearLayout android:id="@+id/bottom_panel" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:orientation="horizontal" 
            android:layout_alignParentBottom="true" > 
            
            <Button android:id="@+id/done" 
                android:layout_width="0dp" 
                android:layout_height="wrap_content" 
                android:layout_weight="1" 
                android:layout_gravity="center_vertical" 
                android:text="done" /> 
                
            <Button android:id="@+id/revert" 
                android:layout_width="0dp" 
                android:layout_height="wrap_content" 
                android:layout_weight="1" 
                android:layout_gravity="center_vertical" 
                android:text="revert" /> 
                
        </LinearLayout> 
        
</RelativeLayout>

相关推荐