现在的位置: 首页 > 综合 > 正文

使用开源组件slidingmenu_library

2013年08月31日 ⁄ 综合 ⁄ 共 3476字 ⁄ 字号 评论关闭

参考: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
         
  1. package com.pps.myrenren.custom;  
  2. import android.content.Context;  
  3. import android.util.AttributeSet;  
  4. import android.widget.ListView;  
  5. /** 
  6.  * 重写ListView->实现Listview和ScrollView的滚动不冲突 
  7.  * @author jiangqingqing 
  8.  * 
  9.  */  
  10. public class MyListView extends ListView {  
  11.     public MyListView(Context context) {  
  12.         super(context);  
  13.     }  
  14.     public MyListView(Context context, AttributeSet attrs) {  
  15.         super(context, attrs);  
  16.     }  
  17.   
  18.     public MyListView(Context context, AttributeSet attrs, int defStyle) {  
  19.         super(context, attrs, defStyle);  
  20.     }  
  21.     @Override  
  22.     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
  23.         int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
  24.                 MeasureSpec.AT_MOST);  
  25.         super.onMeasure(widthMeasureSpec, expandSpec);  
  26.     }  
  27.   
  28. }  
     在该列表的顶部是一个横条,单独写这个布局,然后include进来(left_bottom_top.xml):

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.      >   
  6.     <ImageView   
  7.         android:id="@+id/img_icon_top"  
  8.         android:layout_width="50dip"  
  9.         android:layout_height="50dip"  
  10.         android:layout_centerVertical="true"  
  11.         android:src="@drawable/v_5_9_lbs_nearby_person_portrait_default"  
  12.         />  
  13.      <TextView   
  14.         android:id="@+id/tv_name_top"  
  15.         android:layout_width="wrap_content"  
  16.         android:layout_height="wrap_content"  
  17.         android:text="王老三"  
  18.         android:layout_toRightOf="@id/img_icon_top"  
  19.         android:textSize="20sp"  
  20.         android:layout_centerVertical="true"  
  21.         android:layout_marginLeft="20dip"  
  22.         android:textColor="@color/whilte"/>    
  23.           
  24.      <ImageButton   
  25.          android:id="@+id/imgbtn_toggle_top"  
  26.          android:layout_width="wrap_content"  
  27.          android:layout_height="wrap_content"  
  28.          android:background="@drawable/v5_3_0_profile_arrow_back"  
  29.          android:layout_alignParentRight="true"  
  30.          android:layout_centerInParent="true"  
  31.          android:layout_marginRight="15dip"/>  
  32. </RelativeLayout>  

         

        接着该列表的布局如下fragment_left_bottom.xml

      

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width=

抱歉!评论已关闭.