现在的位置: 首页 > 综合 > 正文

.Net程序员玩转Android开发—(3)登陆页面布局

2017年11月08日 ⁄ 综合 ⁄ 共 3565字 ⁄ 字号 评论关闭

                        这一节我们来看看登陆页面怎样布局,对于刚接触到Android开发的童鞋来说,Android的布局感觉比较棘手,需要结合各种属性进行设置,接下来我们由点入面来

了解安卓中页面怎样布局,登陆页面很简单,两个文本框和一个按钮,页面效果如下:

                       

            1.布局代码

                       点击activity_mail.xml可以查看布局代码

                       点击graphical Layout切换到设计窗体

                        全部代码

                        

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
 
  <LinearLayout android:layout_width="fill_parent"  android:layout_weight="0.9" android:layout_height="fill_parent">
    </LinearLayout>



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

    
    
  <LinearLayout
    android:layout_marginLeft="10px"
    android:layout_marginRight="10px"
    android:gravity="center"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:layout_height="wrap_content">
    
        <TextView android:textSize="8pt"
    android:text="用户名"
    android:layout_weight="0.75"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
            
        </TextView>
        
        <EditText
     android:layout_weight="0.25"
     android:layout_width="fill_parent"
     android:text="请输入用户名"
     android:layout_height="wrap_content">
            
        </EditText>
      
      </LinearLayout>



  <LinearLayout 
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:gravity="center"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
    
        <TextView android:textSize="8pt" 
        android:text="密码"  
         android:layout_weight="0.75"   
          android:layout_width="fill_parent"  
           android:layout_height="wrap_content">
            
        </TextView>
      
        <EditText  android:layout_weight="0.25"   android:layout_width="fill_parent"  android:password="true" android:text="请输入密码" android:layout_height="wrap_content">
        </EditText>
      
      </LinearLayout>
    

      <LinearLayout   android:layout_marginLeft="10px"  android:layout_marginRight="10px" android:gravity="center"    android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">
     <Button android:text="登录"    android:textSize="9pt"  android:layout_width="fill_parent"    android:layout_height="wrap_content">   </Button>
      </LinearLayout>

     <LinearLayout   android:layout_marginLeft="10px"  android:layout_marginRight="10px" android:gravity="center"    android:layout_width="fill_parent" android:orientation="horizontal" android:layout_height="wrap_content">
     <Button android:text="注册 "    android:textSize="9pt"  android:layout_width="fill_parent"    android:layout_height="wrap_content">   </Button>
      </LinearLayout>



  </LinearLayout>
    
</LinearLayout>


            2. 属性说明

                          控件介绍

                                LinearLayout控件: 线性布局控件 ,顾名思义就是以线性方式展示,包括横向和总向两种线性方式

                                  android:orientation="vertical"表示垂直方向,android:orientation="horizontal"表示水平方向

                                TextView控件:显示控件,类似于label标签控件

                                EditText控件:文本框控件,类似于TextBox控件

                               Button按钮控件

                          属性说明

                            layout_width:表示控件相对于父容器的宽度。有三个值 fill_parent   wrap_content  match_parent

                             fill_parent 表示填充整个屏幕宽度

                             wrap_content 表示匹配文字的宽度

                             android:orientation="vertical" 设置水平和垂直方向

                             android:orientation="vertical"  设置控件左边距

                             android:layout_weight 设置控件所占的百分比

                             android:gravity="center"  设置控件内的元素位置

                              android:layout_gravity   用来指控件在父控件中的位置

                             





抱歉!评论已关闭.