android中簡單的佈局佔滿,居底顯示

android 讓一個控件按鈕居於底部的幾種方法
1.採用linearlayout佈局:
android:layout_height="0dp" <!-- 這裏不能設置fill_parent -->
android:layout_weight="1" <!-- 這裏設置layout_weight=1是最關鍵的,否則底部的LinearLayout無法到底部 -->
2. 採用relativelayout佈局:
android:layout_alignParentBottom="true" <!-- 這裏設置layout_alignParentBottom=true是最關鍵的,這個屬性上級必須是RelativeLayout -->

3. 採用 fragment 佈局(activitygroup 已經被棄用不建議使用)

=====================================
1.採用linearlayout佈局:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp" <!-- 這裏不能設置fill_parent -->
android:layout_weight="1" <!-- 這裏設置layout_weight=1是最關鍵的,否則底部的LinearLayout無法到底部 -->
android:orientation="vertical">

</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false" />
</LinearLayout>
</LinearLayout>

2. 採用relativelayout佈局:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" <!-- 這裏設置layout_alignParentBottom=true是最關鍵的,這個屬性上級必須是RelativeLayout -->
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false" />
</LinearLayout>
</RelativeLayout>

3. 採用 fragment 佈局(activitygroup 已經被棄用不建議使用)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<fragment class="com.xuzhi.fragment.FragmentDemoActivity$TitlesFragment" android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent"
/>

<FrameLayout android:id="@+id/details" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground"
></FrameLayout>

</LinearLayout>

==============================================

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章