当前位置:操作系统 > 安卓/Android >>

android登录界面

 

 

  在网上在到一个登录界面感觉挺不错的,给大家分享一下~先看效果图:

 

\

  这个Demo除了按钮、小猫和Logo是图片素材之外,其余的UI都是通过代码实现的。

 


  一、背景

  背景蓝色渐变,是通过一个xml文件来设置的。代码如下:

  background_login.xml


[html]
 <?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient  
        android:startColor="#FFACDAE5" 
        android:endColor="#FF72CAE1" 
        android:angle="45" 
    /> 
</shape> 

  startColor是渐变开始的颜色值,endColor是渐变结束的颜色值,angle是渐变的角度。其中#FFACDAE5中,FF是Alpha值,AC是RGB的R值,DA是RGB的G值,E5是RGB的B值,每个值在00~FF取值,即透明度、红、绿、蓝有0~255的分值,像要设置具体的颜色,可以在PS上的取色器上查看设置。

 

  二、圆角白框

  效果图上面的并不是白框,其实框是白色的,只是设置了透明值,也是靠一个xml文件实现的。

  background_login_div.xml


[html]
 <?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#55FFFFFF" /> 
    <!-- 设置圆角 
    注意: bottomRightRadius是左下角而不是右下角  bottomLeftRadius右下角--> 
    <corners android:topLeftRadius="10dp" android:topRightRadius="10dp" 
        android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"/> 
</shape> 

 


  三、界面的布局

  界面的布局挺简单的,就直接贴代码啦~

  login.xml


[html]
 <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background_login"> 
    <!-- padding 内边距   layout_margin 外边距 
        android:layout_alignParentTop 布局的位置是否处于顶部 --> 
         
    <RelativeLayout  
        android:id="@+id/login_div" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="15dip"         
        android:layout_margin="15dip"  
        android:background="@drawable/background_login_div_bg" > 
        <!-- 账号 --> 
        <TextView  
            android:id="@+id/login_user_input" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_alignParentTop="true" 
            android:layout_marginTop="5dp" 
            android:text="@string/login_label_username" 
            style="@style/normalText"/> 
        <EditText  
            android:id="@+id/username_edit" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:hint="@string/login_username_hint" 
            android:layout_below="@id/login_user_input" 
            android:singleLine="true" 
            android:inputType="text"/> 
        <!-- 密码 text --> 
        <TextView  
            android:id="@+id/login_password_input" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_below="@id/username_edit" 
            android:layout_marginTop="3dp" 
            android:text="@string/login_label_password" 
            style="@style/normalText"/> 
        <EditText  
            android:id="@+id/password_edit" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:layout_below="@id/login_password_input" 
            android:password="true" 
            android:singleLine="true" 
            android:inputType="textPassword" /> 
        <!-- 登录button --> 
补充:移动开发 , Android ,

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,