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.  
    1.采用linearlayout布局:
  2.  
    <LinearLayout
  3.  
    android:layout_width="fill_parent"
  4.  
    android:layout_height="fill_parent"
  5.  
    android:orientation="vertical">
  6.  
     
  7.  
    <LinearLayout
  8.  
    android:id="@+id/content"
  9.  
    android:layout_width="fill_parent"
  10.  
    android:layout_height="0dp" <!-- 這里不能設置fill_parent -->
  11.  
    android:layout_weight="1" <!-- 這里設置layout_weight=1是最關鍵的,否則底部的LinearLayout無法到底部 -->
  12.  
    android:orientation="vertical">
  13.  
     
  14.  
    </LinearLayout>
  15.  
     
  16.  
    <LinearLayout
  17.  
    android:layout_width="fill_parent"
  18.  
    android:layout_height="wrap_content"
  19.  
    android:gravity="bottom"
  20.  
    android:orientation="vertical">
  21.  
    <Button
  22.  
    android:layout_width="wrap_content"
  23.  
    android:layout_height="wrap_content"
  24.  
    android:background="@drawable/runbackground"
  25.  
    android:focusable="false" />
  26.  
    </LinearLayout>
  27.  
    </LinearLayout>

  1.  
    2. 采用relativelayout布局:
  2.  
    <RelativeLayout
  3.  
    android:layout_width="fill_parent"
  4.  
    android:layout_height="fill_parent"
  5.  
    android:orientation="vertical">
  6.  
     
  7.  
    <LinearLayout
  8.  
    android:layout_width="fill_parent"
  9.  
    android:layout_height="fill_parent"
  10.  
    android:orientation="vertical">
  11.  
     
  12.  
    </LinearLayout>
  13.  
     
  14.  
    <LinearLayout
  15.  
    android:layout_width="fill_parent"
  16.  
    android:layout_height="wrap_content"
  17.  
    android:layout_alignParentBottom="true" <!-- 這里設置layout_alignParentBottom=true是最關鍵的,這個屬性上級必須是RelativeLayout -->
  18.  
    android:orientation="vertical">
  19.  
    <Button
  20.  
    android:layout_width="wrap_content"
  21.  
    android:layout_height="wrap_content"
  22.  
    android:background="@drawable/runbackground"
  23.  
    android:focusable="false" />
  24.  
    </LinearLayout>
  25.  
    </RelativeLayout>

  1.  
    3. 采用 fragment 布局(activitygroup 已經被棄用不建議使用)
  2.  
    <?xml version="1.0" encoding="utf-8"?>
  3.  
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
    android:layout_width="match_parent"
  5.  
    android:layout_height="wrap_content"
  6.  
    android:orientation="vertical" >
  7.  
     
  8.  
    <fragment class="com.xuzhi.fragment.FragmentDemoActivity$TitlesFragment" android:id="@+id/titles" android:layout_weight="1"
  9.  
    android:layout_width="0px" android:layout_height="match_parent"
  10.  
    />
  11.  
     
  12.  
    <FrameLayout android:id="@+id/details" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent"
  13.  
    android:background="?android:attr/detailsElementBackground"
  14.  
    > </FrameLayout>
  15.  
     
  16.  
    </LinearLayout>

本人轉載自http://www.cnblogs.com/zdz8207/archive/2012/12/13/2816906.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM