Android 安卓讓LinearLayout放置於底部的方法
阿新 • • 發佈:2018-11-30
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 已經被棄用不建議使用)
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" style="@style/question_css" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout style="@style/question_css" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <FrameLayout android:layout_width="match_parent" android:layout_height="300dp" android:layout_gravity="center_vertical|center_horizontal"> <SurfaceView android:id="@+id/sv_camera_face" android:layout_width="match_parent" android:layout_height="match_parent" /> <SurfaceView android:id="@+id/sv_camera" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> </LinearLayout> <!--問題區域 開始--> <FrameLayout android:id="@+id/fragment_question" android:layout_width="match_parent" android:layout_height="wrap_content"></FrameLayout> <!--問題區域 結束--> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:orientation="vertical" android:layout_weight="1"> </LinearLayout> </LinearLayout> </ScrollView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentBottom="true" android:gravity="bottom" android:orientation="horizontal" android:weightSum="12"> <Button android:id="@+id/btn_former_question" style="@style/question_button_css" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="6" android:text="上一題" /> <Button android:id="@+id/btn_next_question" style="@style/question_button_css" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="6" android:text="下一題" /> </LinearLayout> </RelativeLayout>