android开发我的新浪微博客户端-用户首页面UI篇(5.1)

 

      在前篇完成了用户登录功能后开始用户首页的开发,用户的首页主要的内容是当前登录用户关注的微博列表,本篇先来讲讲UI的实现,效果如上图,整个页面分为上、中、下三部分,上面部分是工具条,显示当前登录用户的昵称以及写微博、刷新两个功能按钮;中间部分是当前用户关注的最新微博列表,下面部分是功能切换栏,用来进行各个功能之间的切换。

      首先新建名为HomeActivity.java的Activity作为用户首页,然后在res/layout目录下新建名为home.xml的Layout,具体代码如下:

代码
<? xml version="1.0" encoding="utf-8" ?>
< LinearLayout
  
xmlns:android ="http://schemas.android.com/apk/res/android"
  android:id
="@+id/layout"
  android:orientation
="vertical"
  android:layout_width
="fill_parent"
  android:layout_height
="fill_parent" >
  
  
< RelativeLayout
  
android:layout_width ="fill_parent"
  android:layout_height
="wrap_content"
  android:layout_margin
="3px" >
  
< ImageView
  
android:layout_width ="wrap_content"
  android:layout_height
="wrap_content"
  android:src
="@drawable/logo_ss" >
  
</ ImageView >
  
< TextView
  
android:id ="@+id/showName"
  android:layout_width
="wrap_content"
  android:layout_height
="wrap_content"
  android:layout_centerInParent
="true"
  android:textColor
="#343434"
  android:textSize
="15px" >
  
</ TextView >
  
< ImageButton
  
android:id ="@+id/writeBtn"
  android:layout_width
="wrap_content"
  android:layout_height
="wrap_content"
  android:layout_toLeftOf
="@+id/refreshBtn"
  android:background
="@drawable/btn_write_selector" >
  
</ ImageButton >
  
< ImageButton
  
android:id ="@+id/refreshBtn"
  android:layout_width
="wrap_content"
  android:layout_height
="wrap_content"
  android:layout_alignParentRight
="true"
  android:layout_marginLeft
="12px"
  android:background
="@drawable/btn_refresh_selector" >
  
</ ImageButton >
  
</ RelativeLayout >
  
  
< LinearLayout
  
android:layout_width ="fill_parent"
  android:layout_height
="wrap_content"
  android:background
="@drawable/hr" >
  
</ LinearLayout >

  
< RelativeLayout
    
android:layout_width ="fill_parent"
    android:layout_height
="fill_parent" >
        
        
< ListView
            
android:id ="@+id/Msglist"
            android:layout_width
="fill_parent"
            android:layout_height
="match_parent"
            android:divider
="@drawable/divider"
            android:dividerHeight
="2px"
            android:layout_margin
="0px"
            android:background
="#BBFFFFFF"
            android:cacheColorHint
="#00000000"
            android:layout_above
="@+id/toolbarLayout"
            android:fastScrollEnabled
="true"   
            android:focusable
="true" >
        
</ ListView >
        
        
< LinearLayout
        
android:id ="@+id/loadingLayout"
        android:layout_width
="wrap_content"
        android:layout_height
="wrap_content"
        android:orientation
="vertical"
        android:visibility
="invisible"
        android:layout_centerInParent
="true" >
            
< ProgressBar
            
android:id ="@+id/loading"
            android:layout_width
="31px"
            android:layout_height
="31px"
            android:layout_gravity
="center"
            style
="@style/progressStyle" >
            
</ ProgressBar >
            
< TextView
            
android:layout_width ="wrap_content"
            android:layout_height
="wrap_content"
            android:text
="正在载入"
            android:textSize
="12px"
            android:textColor
="#9c9c9c"
            android:layout_gravity
="center"
            android:layout_below
="@+id/loading" >
            
</ TextView >
        
</ LinearLayout >
        
        
        
< LinearLayout
        
android:id ="@+id/toolbarLayout"
        android:layout_width
="fill_parent"
        android:layout_height
="44dip"
        android:layout_alignParentBottom
="true" >
        
</ LinearLayout >
  
</ RelativeLayout >
</ LinearLayout >

 

       这个布局首先是一个竖直的根LinearLayout,在这个根LinearLayout里面分别是两个RelativeLayout, 第一个RelativeLayout 用来显示页面的工具条,第二个RelativeLayout用来显示列表以及底部的功能栏,特别主要在这第二个RelativeLayout中有一个id为loadingLayout的LinearLayout是用来显示数据载入中的动画,它的android:visibility属性为invisible(也可以设置成gone,区别:invisible这个View在ViewGroupt中仍保留它的位置,不重新layout 
gone>不可见,但这个View在ViewGroupt中不保留位置,重新layout,那后面的view就会取代他的位置。 ),也就是一开始不显示的意思,接下来看看

<ProgressBar
android:id="@+id/loading"
        android:layout_width="31px"
        android:layout_height="31px"
android:layout_gravity="center"
style="@style/progressStyle">
</ProgressBar>

 

      这个ProgressBar控件就是用来显示动画用的,关键就是 style="@style/progressStyle",在res/values目录下新建名为loadingstyles.xml,内容如下:
代码
<? xml version="1.0" encoding="UTF-8" ?>
< resources >
    
< style  name ="progressStyle"  width ="38"  height ="38"  parent ="@android:style/Widget.ProgressBar.Small" >
        
< item  name ="android:indeterminateDrawable" > @anim/loading </ item >
    
</ style >
</ resources >

 

      接着准备好r1.png - r8.png,八张不同的小图片分别代表每旋转45度图片,八张刚好是360度。把这些图片添加到res/drawable-mdpi目录中。然后在res/anim目录下新建名为loading.xml动画文件,内容如下:

代码
<? xml version="1.0" encoding="UTF-8" ?>
< animation-list  android:oneshot ="false"
  xmlns:android
="http://schemas.android.com/apk/res/android" >
    
< item  android:duration ="200"  android:drawable ="@drawable/r1"   />
    
< item  android:duration ="200"  android:drawable ="@drawable/r2"   />
    
< item  android:duration ="200"  android:drawable ="@drawable/r3"   />
    
< item  android:duration ="200"  android:drawable ="@drawable/r4"   />
    
< item  android:duration ="200"  android:drawable ="@drawable/r5"   />
    
< item  android:duration ="200"  android:drawable ="@drawable/r6"   />
    
< item  android:duration ="200"  android:drawable ="@drawable/r7"   />
    
< item  android:duration ="200"  android:drawable ="@drawable/r8"   />
</ animation-list >

 

    关于Android播放动画实现我是参考http://terryblog.blog.51cto.com/1764499/388226 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值