参考:http://blog.csdn.net/developer_jiangqq/article/details/9466171
今天学习一下使用开源组件slidingmenu_library来模拟实现人人客户端的主页侧滑界面。要模拟实现这个界面,首先要先学习这个开源组件的基本用法,开始今天的学习;
1:slidingmenu_library基本使用;
2:编写代码模仿实现人人客户端主页侧滑;
1.1:开源组件的下载:
该组件开源,我们可以通过把该项目当做libs目录的jar包引入到我们的项目中轻松方便的使用。其中主要实现了侧滑与ActionBar.下载目录如下:
SlidingMenu https://github.com/jfeinstein10/SlidingMenu
ActionBarSherlock https://github.com/JakeWharton/ActionBarSherlock
同时我在资源中已经上传点击下载slidingmenu_library
1.2:该组件的使用方式:
①:下载完该项目,通过Eclipse,import到工作项目中:
②:创建新项目,把该slidingmenu_library,通过libary方式引入进来:具体步骤为(myRenren).右击该项目,选择properties->点击Android->右下方libary,选择add,slidingmenu进来->apply,ok
特别提醒一个问题,因为我之前都是按照这个方式去进行导入,但是新项目总是会出现一个问题,所以你要在项目要引入该开源组件之前,记得看下项目中的libs文件夹,把里面的android-support-v4.jar这个包给删除掉,因为开源组件中已经包含这个包了.
2.1现在正是使用这个组件模式实现人人客户端侧滑主界面:
2.1.1俗话说有图有真相,先看我实现的效果图,比较简单,首页的内容部分也就直接用图片去代替了;
2.1.2:开始实现,分析一下右边列表的那个界面(我自己的实现的思路):
下面是的常用,更多,操作,我设置成了三个listview,自然一个屏幕肯定放不下,所以快可以想到在三个listview的外边加入一个ScrollView。随即这样问题就出来了,ScrollView与Listview发生冲突了,因为Listview本来就带有滚动。这样的问题同样也会发生在ScrollView与GridView中。查阅网上资料给出一种比较常用的方法:重写ListView
- package com.pps.myrenren.custom;
- import android.content.Context;
- import android.util.AttributeSet;
- import android.widget.ListView;
- /**
- * 重写ListView->实现Listview和ScrollView的滚动不冲突
- * @author jiangqingqing
- *
- */
- public class MyListView extends ListView {
- public MyListView(Context context) {
- super(context);
- }
- public MyListView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public MyListView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
- MeasureSpec.AT_MOST);
- super.onMeasure(widthMeasureSpec, expandSpec);
- }
- }
在该列表的顶部是一个横条,单独写这个布局,然后include进来(left_bottom_top.xml):
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- >
- <ImageView
- android:id="@+id/img_icon_top"
- android:layout_width="50dip"
- android:layout_height="50dip"
- android:layout_centerVertical="true"
- android:src="@drawable/v_5_9_lbs_nearby_person_portrait_default"
- />
- <TextView
- android:id="@+id/tv_name_top"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="王老三"
- android:layout_toRightOf="@id/img_icon_top"
- android:textSize="20sp"
- android:layout_centerVertical="true"
- android:layout_marginLeft="20dip"
- android:textColor="@color/whilte"/>
- <ImageButton
- android:id="@+id/imgbtn_toggle_top"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/v5_3_0_profile_arrow_back"
- android:layout_alignParentRight="true"
- android:layout_centerInParent="true"
- android:layout_marginRight="15dip"/>
- </RelativeLayout>
接着该列表的布局如下fragment_left_bottom.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width=