在学习了TextViewEditTextButtonRealtivelayoutlinearlayout等常见布局后就可以实现一个简单的登录界面设计。至于像QQ登录界面和其他比较好看的登录界面,还需要进一步学习一下才能设计出来。

1.界面布局代码

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:gravity="center_horizontal"

    android:background="#87ceeb"

    

     >

 

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_margin="10dp"

        android:text="@string/login_title"

        android:textSize="20sp" />

 

     

     <LinearLayout 

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:orientation="horizontal"

         android:layout_marginTop="20dp"  >

 

         <TextView

             android:paddingLeft="10dp"

             android:layout_width="wrap_content"

             android:layout_height="wrap_content"

             android:text="@string/account" />

 

         <EditText

           android:singleLine="true"

           android:inputType="none"//表示可以输入任何数据,如数字,英文,字符

           android:id="@+id/et_account"

           android:layout_width="220dp"

           android:layout_height="wrap_content"

           android:layout_marginLeft="10dp"

           android:background="@drawable/rounded"

             />

 

            

       

 

   LinearLayout>

   

 

   <LinearLayout

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:layout_marginTop="20dp"

       android:orientation="horizontal" >

         

 

         <TextView 

             android:layout_width="wrap_content"

             android:layout_height="wrap_content"

             android:paddingLeft="5dp"

             android:text="@string/password" />

 

        <EditText

            android:id="@+id/et_pwd"

            android:layout_width="220dp"

            android:layout_height="wrap_content"

            android:layout_marginLeft="20dp"

            android:background="@drawable/rounded"

            android:inputType="textPassword" />

 

     LinearLayout>

     

 

     <Button

         android:background="@drawable/btn"

         android:id="@+id/bt_login"

         android:layout_width="wrap_content"

         android:layout_height="wrap_content"

         android:layout_margin="12dp"

         android:onClick="login"

         android:text="@string/btn_login" />

 

 LinearLayout>

全局采用线性布局linearlayout,在控件位置上用到了android:paddingandroid:layout_margin来调整位置。前者是以父控件为参照,后者是以自身为参照来进行位置的调整。

 

2.EditTextButtonxml文件

 很多朋友都想把边框改成圆形,这里需要在drawable文件中新建xml文件,在xml文件中定义。

  定义EditTextXml文件如下:

 <?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">

    <solid android:color="#FFFFFF"/>

    <stroke android:color="#000000" />

    <padding android:left="10dp"

        >padding>

    <corners android:radius="10dp">corners>

shape>

注释:

android:shape="rectangle" //表示设置边框的形状为矩形

<solid android:color="#FFFFFF"/> //表示设置填充颜色

 <stroke android:color="#000000" /> 表示设置边框颜色

 <corners android:radius="10dp">corners>表示四角的弯曲弧度

定义Buttonxml文件如下:

<?xml version="1.0" encoding="utf-8"?>

 <selector xmlns:android="http://schemas.android.com/apk/res/android" >     

     <item >

         <shape >

            <corners android:radius="10dp" />

            <gradient android:startColor="#add8e6" 

                 android:endColor="#00008b"

                 android:angle="-90"/>

         shape>        

      item>    

 selector>

当定义好以后,只需要在EditTextButton的空间中用一句代码调用即可。

  android:background="@drawable/你自己定义的xml文件名"

3.效果图











  

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. Android(安卓)Studio插件之Android(安卓)Strings.xml To CSV Con
  4. 关于Android使用proguard进行代码混淆
  5. Android(安卓)结束通话--实现黑名单拦截
  6. Android(安卓)- 文件读写操作 总结
  7. Android(安卓)根文件系统启动过程
  8. Android支持的资源
  9. Android应用程序通过JNI控制LED

随机推荐

  1. Android RecyclerView的简单使用
  2. Android 修改系统时间代码
  3. 开源镜像站-Androd镜像
  4. Android Studio电脑不支持HAXM的解决办法
  5. android MVVM ItemViewSelector 实现列表
  6. Android之TabHost的几种使用方法
  7. Android几个常用功能代码(校园助手开发笔
  8. Android——HashMap的替代方案
  9. SmartCard API for Android、Open Mobile
  10. Android -- 文字设置超链接