热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

weibo6

android开发我的新浪微博客户端-登录页面UI篇(4.1)首先回顾一下功能流程当用户开启软件显示载入页面时程序首先去sqlite库查询是否已经保存有用户的新浪微博的UserID

android开发我的新浪微博客户端-登录页面UI篇(4.1)

      

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

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

ExpandedBlockStart.gif代码
xml version="1.0" encoding="utf-8"?>
<LinearLayout
  
xmlns:android&#61;"http://schemas.android.com/apk/res/android"
  android:id
&#61;"&#64;&#43;id/layout"
  android:orientation
&#61;"vertical"
  android:layout_width
&#61;"fill_parent"
  android:layout_height
&#61;"fill_parent">
  
<ImageView
    
android:layout_width&#61;"wrap_content"
    android:layout_height
&#61;"wrap_content"
    android:src
&#61;"&#64;drawable/logo_s"
    android:layout_marginTop
&#61;"5dip"
    android:layout_marginLeft
&#61;"5dip">
  
ImageView>
  
<RelativeLayout
    
android:layout_width&#61;"fill_parent"
    android:layout_height
&#61;"fill_parent">
        
<RelativeLayout
            
android:id&#61;"&#64;&#43;id/iconBtn"
            android:layout_width
&#61;"90px"
            android:layout_height
&#61;"80px"
            android:background
&#61;"&#64;drawable/icon_selector"
            android:layout_above
&#61;"&#64;&#43;id/selectLayout"
            android:layout_centerHorizontal
&#61;"true"
            android:layout_marginBottom
&#61;"20dip">
                
<ImageView
                
android:id&#61;"&#64;&#43;id/icon"
                android:layout_width
&#61;"wrap_content"
                android:layout_height
&#61;"wrap_content"
                android:layout_centerInParent
&#61;"true">
                
ImageView>
        
RelativeLayout>
        
        
<RelativeLayout
        
android:id&#61;"&#64;&#43;id/selectLayout"
        android:layout_width
&#61;"wrap_content"
        android:layout_height
&#61;"wrap_content"
        android:layout_centerInParent
&#61;"true">
            
<EditText
            
android:id&#61;"&#64;&#43;id/iconSelect"
            android:layout_width
&#61;"200px"
            android:layout_height
&#61;"wrap_content" 
            android:maxLength
&#61;"10" 
            android:paddingLeft
&#61;"20px"
            android:editable
&#61;"false"
            android:enabled
&#61;"false"
            android:textSize
&#61;"13px"
            android:background
&#61;"&#64;drawable/input_over" >
            
EditText>
            
<ImageButton 
            
android:id&#61;"&#64;&#43;id/iconSelectBtn"
            android:layout_width
&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content" 
            android:layout_marginRight
&#61;"1.0dip"
            android:layout_alignTop
&#61;"&#64;&#43;id/iconSelect"
            android:layout_alignRight
&#61;"&#64;&#43;id/iconSelect"
            android:layout_alignBottom
&#61;"&#64;&#43;id/iconSelect"
            android:background
&#61;"&#64;drawable/more_selector" >
            
ImageButton>
            
<ImageButton 
            
android:id&#61;"&#64;&#43;id/login"
            android:layout_width
&#61;"40px"
            android:layout_height
&#61;"40px" 
            android:layout_marginLeft
&#61;"5dip"
            android:layout_alignTop
&#61;"&#64;&#43;id/iconSelectBtn"
            android:layout_toRightOf
&#61;"&#64;&#43;id/iconSelectBtn"
            android:layout_alignBottom
&#61;"&#64;&#43;id/iconSelectBtn"
            android:background
&#61;"&#64;drawable/btn_in_selector" >
            
ImageButton>
        
RelativeLayout>
        
        
<RelativeLayout
        
android:layout_width&#61;"fill_parent"
        android:layout_height
&#61;"44dip"
        android:layout_alignParentBottom
&#61;"true"
        android:background
&#61;"#BB768e95">
            
<LinearLayout
            
android:id&#61;"&#64;&#43;id/addLayout"
            android:layout_width
&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:orientation
&#61;"vertical"
            android:layout_alignParentLeft
&#61;"true"
            android:gravity
&#61;"center"
            android:layout_marginTop
&#61;"3px">
            
<ImageButton
            
android:id&#61;"&#64;&#43;id/addIcon"
            android:layout_width
&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:background
&#61;"&#64;drawable/add_selector">
            
ImageButton>
            
<TextView
            
android:layout_width&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:textColor
&#61;"#ffffff"
            android:textSize
&#61;"12px"
            android:text
&#61;"添加账号">
            
TextView>
            
LinearLayout>
            
<LinearLayout
            
android:id&#61;"&#64;&#43;id/exitLayout"
            android:layout_width
&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:orientation
&#61;"vertical"
            android:layout_centerInParent
&#61;"true"
            android:gravity
&#61;"center"
            android:layout_marginTop
&#61;"3px">
            
<ImageButton
            
android:id&#61;"&#64;&#43;id/exitIcon"
            android:layout_width
&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:background
&#61;"&#64;drawable/exit_selector">
            
ImageButton>
            
<TextView
            
android:layout_width&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:textColor
&#61;"#ffffff"
            android:textSize
&#61;"12px"
            android:text
&#61;"退出软件">
            
TextView>
            
LinearLayout>
            
<LinearLayout
            
android:id&#61;"&#64;&#43;id/delLayout"
            android:layout_width
&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:orientation
&#61;"vertical"
            android:layout_alignParentRight
&#61;"true"
            android:gravity
&#61;"center"
            android:layout_marginTop
&#61;"3px">
            
<ImageButton
            
android:id&#61;"&#64;&#43;id/delIcon"
            android:layout_width
&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:background
&#61;"&#64;drawable/del_selector">
            
ImageButton>
            
<TextView
            
android:layout_width&#61;"wrap_content"
            android:layout_height
&#61;"wrap_content"
            android:textColor
&#61;"#ffffff"
            android:textSize
&#61;"12px"
            android:text
&#61;"删除账号">
            
TextView>
            
LinearLayout>
        
RelativeLayout>
  
RelativeLayout>
LinearLayout>

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

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

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

 ExpandedBlockStart.gif代码

xml version&#61;"1.0" encoding&#61;"utf-8"?>
<resources>
    
<style name&#61;"dialog2" parent&#61;"&#64;android:style/Theme.Dialog">
        
<item name&#61;"android:windowFrame">&#64;nullitem>
        
<item name&#61;"android:windowIsFloating">trueitem>
        
<item name&#61;"android:windowIsTranslucent">falseitem>
        
<item name&#61;"android:windowNoTitle">trueitem>
        
<item name&#61;"android:windowBackground">&#64;drawable/mask_bgitem>
        
<item name&#61;"android:backgroundDimEnabled">trueitem>
    
style>
resources>

接下来还需要定义选择列表的layout&#xff0c;新建名为dialog2.xml的layout文件&#xff0c;内容如下&#xff1a;

 ExpandedBlockStart.gif代码

xml version&#61;"1.0" encoding&#61;"utf-8"?>
<LinearLayout
  
xmlns:android&#61;"http://schemas.android.com/apk/res/android"
  android:layout_width
&#61;"wrap_content"
  android:layout_height
&#61;"wrap_content"
  android:orientation
&#61;"vertical"
  android:padding
&#61;"4dip">
  
<ListView
        
android:id&#61;"&#64;&#43;id/list"
        android:layout_width
&#61;"240px"
        android:layout_height
&#61;"220px"
        android:divider
&#61;"#f1f2f2"
        android:dividerHeight
&#61;"1px"
        android:layout_margin
&#61;"5px"
        android:background
&#61;"#ffffff"
        android:cacheColorHint
&#61;"#00000000">
    
ListView>
LinearLayout>

完成了layout和样式文件的编写&#xff0c;接下来就是把dialogStyles2.xml样式文件和dialog2.xml的列表layout用起来&#xff0c;当点击id为iconSelectBtn的ImageButton时显示用户选择窗口&#xff0c;在LoginActivity的onCreate方法中添加如下代码&#xff1a;

ExpandedBlockStart.gif代码
public void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        
        LinearLayout layout
&#61;(LinearLayout)findViewById(R.id.layout);
        
//背景自动适应
        AndroidHelper.AutoBackground(this, layout, R.drawable.bg_v, R.drawable.bg_h);
        
        ImageButton iconSelectBtn
&#61;(ImageButton)findViewById(R.id.iconSelectBtn);
        iconSelectBtn.setOnClickListener(
new OnClickListener(){
            &#64;Override
            
public void onClick(View v) {
                View diaView
&#61;View.inflate(LoginActivity.this, R.layout.dialog2, null);
                dialog
&#61;new Dialog(LoginActivity.this,R.style.dialog2);
                dialog.setContentView(diaView);
                dialog.show();
                
                ......
            }
            
        });

 

     到这里登录的UI部分就实现的差不多了&#xff0c;剩下的都是一些功能部分代码用来实现从sqlite中账号列表的获取&#xff0c;以及点击选择等交互操作等&#xff0c;这些在下一篇中来继续的讲。

分类: Andr



推荐阅读
  • 在一对一直播源码使用过程中,有时会出现软键盘切换闪屏问题,就是当切换表情的时候屏幕会跳动,因此要对一对一直播源码表情面板无缝切换进行优化。 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • 这两天用到了ListView,写下遇到的一些问题。首先是ListView本身与子控件的焦点问题,比如我这里子控件用到了Button,在需要ListView中的根布局属性上加上下面的这一个属性:and ... [详细]
  • 本文详细介绍了MySQL表分区的创建、增加和删除方法,包括查看分区数据量和全库数据量的方法。欢迎大家阅读并给予点评。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • Oracle seg,V$TEMPSEG_USAGE与Oracle排序的关系及使用方法
    本文介绍了Oracle seg,V$TEMPSEG_USAGE与Oracle排序之间的关系,V$TEMPSEG_USAGE是V_$SORT_USAGE的同义词,通过查询dba_objects和dba_synonyms视图可以了解到它们的详细信息。同时,还探讨了V$TEMPSEG_USAGE的使用方法。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • 本文提供了关于数据库设计的建议和注意事项,包括字段类型选择、命名规则、日期的加入、索引的使用、主键的选择、NULL处理、网络带宽消耗的减少、事务粒度的控制等方面的建议。同时还介绍了使用Window Functions进行数据处理的方法。通过遵循这些建议,可以提高数据库的性能和可维护性。 ... [详细]
  • 开发笔记:(002)spring容器中bean初始化销毁时执行的方法及其3种实现方式
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了(002)spring容器中bean初始化销毁时执行的方法及其3种实现方式相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 在最近的一系列文章,对midipadAPP,有一个关于一个radialgradiant渲染每个padview利用的探讨,对审美的原因&#x ... [详细]
  • 延迟注入工具(python)的SQL脚本
    本文介绍了一个延迟注入工具(python)的SQL脚本,包括使用urllib2、time、socket、threading、requests等模块实现延迟注入的方法。该工具可以通过构造特定的URL来进行注入测试,并通过延迟时间来判断注入是否成功。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 本文介绍了Oracle存储过程的基本语法和写法示例,同时还介绍了已命名的系统异常的产生原因。 ... [详细]
  • REVERT权限切换的操作步骤和注意事项
    本文介绍了在SQL Server中进行REVERT权限切换的操作步骤和注意事项。首先登录到SQL Server,其中包括一个具有很小权限的普通用户和一个系统管理员角色中的成员。然后通过添加Windows登录到SQL Server,并将其添加到AdventureWorks数据库中的用户列表中。最后通过REVERT命令切换权限。在操作过程中需要注意的是,确保登录名和数据库名的正确性,并遵循安全措施,以防止权限泄露和数据损坏。 ... [详细]
author-avatar
CH_Double_C
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有