Chinaunix首页 | 论坛 | 博客
  • 博客访问: 51912
  • 博文数量: 18
  • 博客积分: 454
  • 博客等级: 下士
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-08 22:40
文章分类
文章存档

2012年(18)

最近访客

分类: 嵌入式

2012-01-08 23:07:59

2011-4-21 14:30:00 上传
2.png

      首先回顾一下功能流程当用户开启软件显示载入页面时程序首先去sqlite库查询是否已经保存有用户的新浪微博的UserID号、Access Token、Access Secret的记录如果没有一条记录那么跳转到用户授权功能页面,这个已经由上面两篇文章实现了,如果有记录那么页面跳转到用户登录页面,也就是本篇以及下篇要实现的功能,本篇讲UI的实现,本项目支持多微博账号了,也就是用户可以设置多个微博账号,登录的时候选择其中的一个登录,具体效果如上图,新建名 LoginActivity.java的Activity并且在Manifest.xml中进行相应配置,这个页面就是我们要实现的用户登录页面。

      看上面的效果,首先页面分3部分实现,背景部分、底部菜单部分、用户选择以及头像显示部分,首先在res/layout的目录下新建名为login.xml的layout,然后根据页面显示要求编写如下的布局控制:



  1.   xmlns:=""
  2.   android:id="@+id/layout"
  3.   android:orientation="vertical"
  4.   android:layout_width="fill_parent"
  5.   android:layout_height="fill_parent">
  6.   
  7.     android:layout_width="wrap_content"
  8.     android:layout_height="wrap_content"
  9.     android:src="@drawable/logo_s"
  10.     android:layout_marginTop="5dip"
  11.     android:layout_marginLeft="5dip">
  12.   
  13.   
  14.     android:layout_width="fill_parent"
  15.     android:layout_height="fill_parent">
  16.         
  17.             android:id="@+id/iconBtn"
  18.             android:layout_width="90px"
  19.             android:layout_height="80px"
  20.             android:background="@drawable/icon_selector"
  21.             android:layout_above="@+id/selectLayout"
  22.             android:layout_centerHorizontal="true"
  23.             android:layout_marginBottom="20dip">
  24.                
  25.                 android:id="@+id/icon"
  26.                 android:layout_width="wrap_content"
  27.                 android:layout_height="wrap_content"
  28.                 android:layout_centerInParent="true">
  29.                
  30.         
  31.         
  32.         
  33.         android:id="@+id/selectLayout"
  34.         android:layout_width="wrap_content"
  35.         android:layout_height="wrap_content"
  36.         android:layout_centerInParent="true">
  37.             
  38.             android:id="@+id/iconSelect"
  39.             android:layout_width="200px"
  40.             android:layout_height="wrap_content"
  41.             android:maxLength="10"
  42.             android:paddingLeft="20px"
  43.             android:editable="false"
  44.             android:enabled="false"
  45.             android:textSize="13px"
  46.             android:background="@drawable/input_over" >
  47.             
  48.             
  49.             android:id="@+id/iconSelectBtn"
  50.             android:layout_width="wrap_content"
  51.             android:layout_height="wrap_content"
  52.             android:layout_marginRight="1.0dip"
  53.             android:layout_alignTop="@+id/iconSelect"
  54.             android:layout_alignRight="@+id/iconSelect"
  55.             android:layout_alignBottom="@+id/iconSelect"
  56.             android:background="@drawable/more_selector" >
  57.             
  58.             
  59.             android:id="@+id/login"
  60.             android:layout_width="40px"
  61.             android:layout_height="40px"
  62.             android:layout_marginLeft="5dip"
  63.             android:layout_alignTop="@+id/iconSelectBtn"
  64.             android:layout_toRightOf="@+id/iconSelectBtn"
  65.             android:layout_alignBottom="@+id/iconSelectBtn"
  66.             android:background="@drawable/btn_in_selector" >
  67.             
  68.         
  69.         
  70.         
  71.         android:layout_width="fill_parent"
  72.         android:layout_height="44dip"
  73.         android:layout_alignParentBottom="true"
  74.         android:background="#BB768e95">
  75.             
  76.             android:id="@+id/addLayout"
  77.             android:layout_width="wrap_content"
  78.             android:layout_height="wrap_content"
  79.             android:orientation="vertical"
  80.             android:layout_alignParentLeft="true"
  81.             android:gravity="center"
  82.             android:layout_marginTop="3px">
  83.             
  84.             android:id="@+id/addIcon"
  85.             android:layout_width="wrap_content"
  86.             android:layout_height="wrap_content"
  87.             android:background="@drawable/add_selector">
  88.             
  89.             
  90.             android:layout_width="wrap_content"
  91.             android:layout_height="wrap_content"
  92.             android:textColor="#ffffff"
  93.             android:textSize="12px"
  94.             android:text="添加账号">
  95.             
  96.             
  97.             
  98.             android:id="@+id/exitLayout"
  99.             android:layout_width="wrap_content"
  100.             android:layout_height="wrap_content"
  101.             android:orientation="vertical"
  102.             android:layout_centerInParent="true"
  103.             android:gravity="center"
  104.             android:layout_marginTop="3px">
  105.             
  106.             android:id="@+id/exitIcon"
  107.             android:layout_width="wrap_content"
  108.             android:layout_height="wrap_content"
  109.             android:background="@drawable/exit_selector">
  110.             
  111.             
  112.             android:layout_width="wrap_content"
  113.             android:layout_height="wrap_content"
  114.             android:textColor="#ffffff"
  115.             android:textSize="12px"
  116.             android:text="退出软件">
  117.             
  118.             
  119.             
  120.             android:id="@+id/delLayout"
  121.             android:layout_width="wrap_content"
  122.             android:layout_height="wrap_content"
  123.             android:orientation="vertical"
  124.             android:layout_alignParentRight="true"
  125.             android:gravity="center"
  126.             android:layout_marginTop="3px">
  127.             
  128.             android:id="@+id/delIcon"
  129.             android:layout_width="wrap_content"
  130.             android:layout_height="wrap_content"
  131.             android:background="@drawable/del_selector">
  132.             
  133.             
  134.             android:layout_width="wrap_content"
  135.             android:layout_height="wrap_content"
  136.             android:textColor="#ffffff"
  137.             android:textSize="12px"
  138.             android:text="删除账号">
  139.             
  140.             
  141.         
  142.   
复制代码

正对上面的login.xml的layout进行一下说明,背景部分前面已经讲过了这里也就不重复。

      底部菜单实现,原本我是采用GridView实现的非常的方便但是后来由于显示位置不好控制改成了用RelativeLayout和 LinearLayout嵌套的方式,实现的比较土但是达到了显示需求,首先是一个最外面的RelativeLayout目的是用来实现底部对齐显示,并且把这个RelativeLayout的背景设置为浅蓝色半透明的效果,关键这2 行:android:layout_alignParentBottom="true"和 android:background="#BB768e95"。然后是在RelativeLayout内部添加3个LinearLayout分别是用来显示添加账号、退出软件、删除账号3个功能按钮菜单,并且分别设置为左对齐、居中对齐、右对齐,3个LinearLayout都设置为垂直布局 android: orientation="vertical",然后每LinearLayout添加相应的图片和文字。

     用户选择以及头像显示部分,这块分成3小块,用来显示用户头像的ImageView、用来显示用户名字并且点击可以出现选择列表的 EditText、用来点击进入当前选择用户首页的功能按钮ImageButton,这3小块的布局实现也是采用elativeLayout和 LinearLayout相互嵌套配合的方式实现的具体参考login.xml。这里重点说说这个账号选择列表弹出窗口的实现,当点击下拉箭头按钮的时候弹出并显示,这个是用Dialog控件实现,首先准备好圆角的半透明背景图mask_bg.png然后添加到res/drawable-mdpi文件夹下,接着自定义一个Dialog样式文件,在res/values目录下新建名为dialogStyles2.xml的resources文件,在用户授权验证页面的时候我们也自定义过类似的Dialog的样式,具体解释可以参考前面的户授权验证页面功能,内容如下:



  1.    
复制代码

接下来还需要定义选择列表的layout,新建名为dialog2.xml的layout文件,内容如下:

  1.   xmlns:android=""
  2.   android:layout_width="wrap_content"
  3.   android:layout_height="wrap_content"
  4.   android:orientation="vertical"
  5.   android:padding="4dip">
  6.   
  7.         android:id="@+id/list"
  8.         android:layout_width="240px"
  9.         android:layout_height="220px"
  10.         android:divider="#f1f2f2"
  11.         android:dividerHeight="1px"
  12.         android:layout_margin="5px"
  13.         android:background="#ffffff"
  14.         android:cacheColorHint="#00000000">
  15.    
复制代码
完成了layout和样式文件的编写,接下来就是把dialogStyles2.xml样式文件和dialog2.xml的列表layout用起来,当点击 id为iconSelectBtn的ImageButton时显示用户选择窗口,在LoginActivity的onCreate方法中添加如下代码:
  1. public void onCreate(Bundle savedInstanceState) {
  2.         super.onCreate(savedInstanceState);
  3.         setContentView(R.layout.login);
  4.         
  5.         LinearLayout layout=(LinearLayout)findViewById(R.id.layout);
  6.         //背景自动适应
  7.         AndroidHelper.AutoBackground(this, layout, R.drawable.bg_v, R.drawable.bg_h);
  8.         
  9.         ImageButton iconSelectBtn=(ImageButton)findViewById(R.id.iconSelectBtn);
  10.         iconSelectBtn.setOnClickListener(new OnClickListener(){
  11.             @Override
  12.             public void onClick(View v) {
  13.                 View diaView=View.inflate(LoginActivity.this, R.layout.dialog2, null);
  14.                 dialog=new Dialog(LoginActivity.this,R.style.dialog2);
  15.                 dialog.setContentView(diaView);
  16.                 dialog.show();
  17.                
  18.                 ......
  19.             }
  20.             
  21.         });
复制代码
到这里登录的UI部分就实现的差不多了,剩下的都是一些功能部分代码用来实现从sqlite中账号列表的获取,以及点击选择等交互操作等,这些在下一篇中来继续的讲。

阅读(1035) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~