码迷,mamicode.com
首页 > 其他好文 > 详细

LinearLayout实现一个简易的登陆界面

时间:2016-06-16 01:33:03      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:

今天通过学习六大布局中第一种布局方式:LinearLayout ,就拿来去做一个简易的登陆界面

存在的问题: LinearLayout中实现水平方向上的两个View一个居左,一个居右的效果,感觉这个才是学以致用

界面如下:

技术分享

 

解决上面所存在问题的方案:通过巧妙地使用 android:layout_weight 达到所想要的效果

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:tools="http://schemas.android.com/tools"
  4     android:layout_width="match_parent"
  5     android:layout_height="fill_parent"
  6     android:paddingBottom="@dimen/activity_vertical_margin"
  7     android:paddingLeft="@dimen/activity_horizontal_margin"
  8     android:paddingRight="@dimen/activity_horizontal_margin"
  9     android:paddingTop="@dimen/activity_vertical_margin"
 10     tools:context="com.activety.log.MainActivity"
 11     android:orientation="vertical"
 12 
 13     >
 14       <View
 15        android:layout_width="match_parent"
 16        android:layout_height="1dp"
 17        android:background="#000000"/>
 18 
 19        <LinearLayout
 20            android:id="@+id/first"
 21            android:layout_width="match_parent"
 22            android:layout_height="40dp"
 23            android:orientation="horizontal">
 24 
 25          <View
 26              android:layout_width="1dp"
 27              android:layout_height="match_parent"
 28              android:background="#000000"/>
 29 
 30           <EditText
 31               android:layout_width="wrap_content"
 32               android:layout_height="match_parent"
 33               android:layout_weight="1"
 34               android:background="#00000000"
 35               android:layout_gravity="center"
 36               android:maxLength="20"
 37               android:hint=" 账号                            4-20位中文/字母/数字"
 38               android:textColorHint="#0000FF"/>
 39 
 40           <View
 41               android:layout_width="1dp"
 42               android:layout_height="match_parent"
 43               android:background="#000000"/>
 44 
 45        </LinearLayout>
 46 
 47    <View
 48        android:layout_width="match_parent"
 49        android:layout_height="1dp"
 50        android:background="#000000"/>
 51 
 52     <LinearLayout
 53         android:id="@+id/Second"
 54         android:layout_width="match_parent"
 55         android:layout_height="40dp"
 56         android:orientation="horizontal">
 57 
 58         <View
 59             android:layout_width="1dp"
 60             android:layout_height="match_parent"
 61             android:background="#000000"/>
 62 
 63         <EditText
 64             android:layout_width="wrap_content"
 65             android:layout_height="match_parent"
 66             android:layout_weight="1"
 67             android:background="#00000000"
 68             android:layout_gravity="center"
 69             android:maxLength="20"
 70             android:hint=" 密码                                      6-16位字母/数字"
 71             android:textColorHint="#0000FF"/>
 72 
 73         <View
 74             android:layout_width="1dp"
 75             android:layout_height="match_parent"
 76             android:background="#000000"/>
 77 
 78     </LinearLayout>
 79 
 80     <View
 81         android:layout_width="match_parent"
 82         android:layout_height="1dp"
 83         android:background="#000000"/>
 84     <LinearLayout
 85         android:id="@+id/Third"
 86         android:layout_width="match_parent"
 87         android:layout_height="40dp"
 88         android:orientation="horizontal">
 89 
 90         <View
 91             android:layout_width="1dp"
 92             android:layout_height="match_parent"
 93             android:background="#000000"/>
 94 
 95         <EditText
 96             android:layout_width="wrap_content"
 97             android:layout_height="match_parent"
 98             android:layout_weight="1"
 99             android:background="#00000000"
100             android:layout_gravity="center"
101             android:maxLength="20"
102             android:hint=" 昵称                            4-20位中文/字母/数字"
103             android:textColorHint="#0000FF"/>
104 
105         <View
106             android:layout_width="1dp"
107             android:layout_height="match_parent"
108             android:background="#000000"/>
109 
110     </LinearLayout>
111 
112     <View
113         android:layout_width="match_parent"
114         android:layout_height="1dp"
115         android:background="#000000"/>
116     <LinearLayout
117         android:id="@+id/Fourth"
118         android:layout_width="match_parent"
119         android:layout_height="40dp"
120         android:orientation="horizontal">
121 
122         <View
123             android:layout_width="1dp"
124             android:layout_height="match_parent"
125             android:background="#000000"/>
126 
127         <RadioButton
128         android:layout_width="wrap_content"
129         android:layout_height="fill_parent"
130         android:layout_weight="1"
131         android:text="我是帅哥"
132         android:textColor="#0000ff"/>
133 
134         <View
135             android:layout_width="1dp"
136             android:layout_height="match_parent"
137             android:background="#000000"/>
138 
139         <RadioButton
140             android:layout_width="wrap_content"
141             android:layout_height="fill_parent"
142             android:layout_weight="1"
143             android:text="我是美女"
144             android:textColor="#0000ff"/>
145 
146 
147         <View
148             android:layout_width="1dp"
149             android:layout_height="match_parent"
150             android:background="#000000"/>
151 
152     </LinearLayout>
153 
154     <View
155         android:layout_width="match_parent"
156         android:layout_height="1dp"
157         android:background="#000000"/>
158   
159     <Button
160         android:layout_width="match_parent"
161         android:layout_height="45dp"
162         android:text="完成"
163         android:layout_marginTop="10dp"
164         android:textColor="#FFFFFF"
165         android:background="#0000FF"
166         />
167 
168 </LinearLayout>

 

 

核心代码:当给EditText设置了android:layout_weight="1" 这个属性,就会将整个LinearLayout 布局给撑起来,这是解决这个问题的关键之处。
 1 <LinearLayout
 2            android:id="@+id/first"
 3            android:layout_width="match_parent"
 4            android:layout_height="40dp"
 5            android:orientation="horizontal">
 6 
 7          <View
 8              android:layout_width="1dp"
 9              android:layout_height="match_parent"
10              android:background="#000000"/>
11 
12           <EditText
13               android:layout_width="wrap_content"
14               android:layout_height="match_parent"
15               android:layout_weight="1"
16               android:background="#00000000"
17               android:layout_gravity="center"
18               android:maxLength="20"
19               android:hint=" 账号                            4-20位中文/字母/数字"
20               android:textColorHint="#0000FF"/>
21 
22           <View
23               android:layout_width="1dp"
24               android:layout_height="match_parent"
25               android:background="#000000"/>
26 
27        </LinearLayout>

 

LinearLayout实现一个简易的登陆界面

标签:

原文地址:http://www.cnblogs.com/Donoy/p/5589514.html

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