码迷,mamicode.com
首页 > 移动开发 > 详细

Android 使控件位于界面底部

时间:2014-12-29 21:36:06      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:android   布局   控件   界面   linearlayout   

Android 如何使控件位于界面底部

    使控件位于界面底部有很多种办法,下面我就分情况说一下:
  一、LinearLayout布局中:
         把握三个原则即可轻松使控件位于界面底部:
          1、最外层父容器LinearLayout设置高度  layout_height="match_parent"
             2、 内层LinearLayout设置    layout_weight="1" 并且 layout_height="0dp"
             3、内层LinearLayout 设置其中控件位置:android:gravity="center|bottom"
           技术分享
下面用实际例子来验证(如上图)。
    布局文件代码如下:
                
                       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                              xmlns:tools="http://schemas.android.com/tools"
                               android:layout_width="fill_parent"
                               android:layout_height="match_parent"
                               android:paddingLeft="@dimen/activity_horizontal_margin"
                              android:orientation="vertical"
                              tools:context=".MainActivity">


                      <TextView
                               android:text="@string/hello_world"
                               android:layout_weight="0"
                               android:layout_width="wrap_content"
                               android:layout_height="wrap_content" />

                          <LinearLayout
                                android:layout_width="fill_parent"
                                android:layout_height="0dp"
                                android:orientation="horizontal"
                                android:gravity="bottom|center"
                                android:layout_weight="1">
                              <EditText
                                        android:minWidth="280dp"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="请输入内容"/>
                             <Button
                                       android:layout_width="wrap_content"
                                       android:layout_height="wrap_content"
                                       android:text="发送"/>
                        </LinearLayout>
                  </LinearLayout>
              注意:使用LinearLayout布局时不要忘了设置控件的排序方式哦 android:orientation 这个属性不设置会报错哦
     二、RelativeLayout布局中
                 这种布局方式比较灵活,设置起来也方便,只需要在控件中添加 
                 android:alignParentBottom 
              这个属性即可让控件位于屏幕下方。      

Android 使控件位于界面底部

标签:android   布局   控件   界面   linearlayout   

原文地址:http://blog.csdn.net/u010838555/article/details/42241751

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!