• 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
  • 相关阅读:
    Git的初步学习
    Git的初步学习
    微信小程序我的界面
    微信小程序我的界面
    Day2:html和css
    Day2:html和css
    Day1:html和css
    Day1:html和css
    Java之JDK7的新语法探索
    Java之JDK7的新语法探索
  • 原文地址:https://www.cnblogs.com/yelanggu/p/10717645.html
Copyright © 2020-2023  润新知