今天由于做练习项目用,要用到像网易新闻那样的界面布局,找了很多资料,快速开发的工具特别多,现有的源码也特别多,但是觉得直接复制到自己的代码中,又嫌它太大了,于是决定从现有的资源学习并试着整一个,减少代码量,以后工作中如果遇到就打算直接套入,当然了,对于大侠来说,UI简直就是小菜一碟,但是对于菜鸟的我来说,还是处于慢慢积累的阶段中,从开始学android到现在,自己的代码库也渐渐多了很多实用的东西起来,我觉得建立自己的代码库是每个人应该有的好习惯。。个人建议,不喜勿喷。好了,不废话,同样先上图。
左边是网易新闻的界面,而右边是运行的效果图。。。
今天琢磨了一整个下午,写博客也是为了好方便自己温故下。。。这里我就大概介绍一些吧
首先是主界面的布局:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="40.0dip"
android:background="#fff3f3f3"
android:orientation="horizontal" >
android:id="@+id/rl_column"
android:layout_width="0dp"
android:layout_height="40.0dip"
android:layout_weight="1.0" >
android:id="@+id/mColumnHorizontalScrollView"
android:layout_width="match_parent"
android:layout_height="40.0dip"
android:scrollbars="none" >
android:id="@+id/mRadioGroup_content"
android:layout_width="fill_parent"
android:layout_height="40.0dip"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="10.0dip"
android:paddingRight="10.0dip" />
android:id="@+id/shade_left"
android:layout_width="10.0dip"
android:layout_height="40.0dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/channel_leftblock"
android:visibility="gone" />
android:id="@+id/shade_right"
android:layout_width="10.0dip"
android:layout_height="40.0dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/channel_rightblock"
android:visibility="visible" />
android:id="@+id/ll_more_columns"
android:layout_width="wrap_content"
android:layout_height="40.0dip" >
android:id="@+id/button_more_columns"
android:layout_width="40.0dip"
android:layout_height="40.0dip"
android:layout_gravity="center_vertical"
android:src="@drawable/channel_glide_day_bg" />
android:id="@+id/category_line"
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:background="#ffdddddd" />
android:id="@+id/mPullRefreshView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/gray_white" >
android:id="@+id/mListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="@drawable/list_divider"
android:dividerHeight="1px" />
从布局文件可以看到,整个界面由顶部的频道栏目ColumnHorizontalScrollView和下面的PullToRefreshView组成,在看源码的时候,只要将这两个控件进行分开学习更好理解思路。。。1.ColumnHorizontalScrollView是一个继承HorizontalScrollView的控件,大家都知道,由于移动设备物理显示空间一般有限,不可能一次性的把所有要显示的内容都显示在屏幕上,所以就可以通过滚动视图来向用户展示数据,而HorizontalScrollView就是能实现这种需求的类之一
2.PullToRefreshView大家都熟到不行了吧,我们都是通过ListView的addHeaderView()方法向listView的头部添加布局,以达到下拉刷新,上拉加载的效果,只不过这里是往ListView的头部添加一个ViewPager,并实现下拉刷新,上拉加载的需求。
大概思路就介绍到这,今天也是整了好久,可能对于有一定工作经验的人来讲,解决这种需求早已是5分钟的事,初来乍到,也不敢已下载这个框架,那个框架的,不然以后也只停留在我知道有这么个框架的层面上了,所以还是知道下如何实现,以及自己实践下的好,感觉这种界面很是常见,以后肯定不止遇到一两次,因此这篇博客只是作为简单的思路介绍,帮助自己以后回顾,对于源码我会上传,考虑到它对我以后的帮助性,我会在接下来的时间,对现在整好的代码进行优化,并提高它的灵活性,以便以后的使用。。。