在学习了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.效果图


Android一个简易的登录界面_第1张图片

Android一个简易的登录界面_第2张图片








  

更多相关文章

  1. Android 根文件系统启动过程
  2. Android资源文件简介
  3. android 五大布局文件
  4. AndroidManifest配置文件介绍
  5. 自定义View系列教程06--详解View的Touch事件处理
  6. android根据uri或文件绝对路径获取文件基本信息
  7. android 使用代码方式创建自定义progressBar——自定义控件学习(
  8. Android 动画系列之自定义补间动画
  9. 【自定义控件系列四】android绘制实战(一)通过Canvas+Path+Paint

随机推荐

  1. mysql 数据库中表不同 但是列名相同,怎么
  2. SQL从结果数据库中选择subCode及其得分,并
  3. 什么时候最推荐使用mysql_real_escape_st
  4. Atitit 数据库 标准库 &#160;sdk 函数库
  5. mysql如何导出HTML?
  6. wampserver无法启动之mysql疑难杂症
  7. Linux下mysql数据库root无法登录的情况
  8. CentOS 6.5下源码安装mysql 5.5
  9. 在MySQL中将数据从LATIN1转换为UTF8
  10. mysql升级的一些踩坑点