Android仿QQ分组实现二级菜单展示

  

本文实例为大家分享了Android仿QQ分组实现二级菜单展示的具体代码,供大家参考,具体内容如下

  

首先展示下要实现的效果

  

 Android仿QQ分组实现二级菜单展示

  

动态查看请看链接

  

<强> 1。首先要定义,也就是二级展示的项目

  

child_item.xml         & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;使用   android: id=癅 + id/list_friend”   xmlns: android=" http://schemas.android.com/apk/res/android "   android: layout_width=" match_parent "   android: layout_height=癿atch_parent”比;      & lt; com.makeramen.roundedimageview。RoundedImageView xmlns:应用=" http://schemas.android.com/apk/res-auto "   android: id=癅 + id/iv”   android: layout_width=" 60 dp "   android: layout_height=" 60 dp "   android:重力=" center_horizontal "   android: src=" https://www.yisu.com/zixun/# 000000”   应用:riv_border_color=" # 333333 "   应用:riv_border_width=叭荨?   应用:riv_corner_radius=" 10底”   应用:riv_mutate_background=" true "   应用:riv_oval=" true "/比;      LinearLayout & lt;   android: layout_width=" match_parent "   android: layout_height=" 60 dp "   android: layout_toRightOf=" @ id/iv”   面向android:=按怪薄北?      & lt; TextView   android: id=癅 + id/friendname”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_weight=" 1 "   android:文本="好友1”   android:输入textColor=" # 000000 "   android: textSize=" 30 dp/比;      & lt; TextView   android: id=癅 + id/座右铭”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_weight=" 1 "   android:文本="这是好友1的签名”   android:输入textColor=" # 000000 "   android: textSize=" 20 dp/比;      & lt;/LinearLayout>   & lt;/RelativeLayout>      

效果如下图所示:

  

 Android仿QQ分组实现二级菜单展示

  

<强> 2。其次,设置分组项目

  

groupitem.xml         & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android: layout_marginBottom=" 10 dp”比;      & lt; ImageView   android: id=癅 + id/triangle_right”   android: layout_width=" 20 dp”   android: layout_height=" 40 dp "   android: layout_alignParentLeft=" true "   android:背景=癅drawable/triangle_right”/比;      & lt; TextView   android: id=癅 + id/headtext”   android: layout_width=" match_parent "   android: layout_height=" 40 dp "   android: layout_toLeftOf=癅 + id/online_people_num”   android: layout_toRightOf=癅 + id/triangle_right”   android:背景=" # E9E9E9”   android:文本="我的好友”   android: textSize=?5 dp/比;      & lt; TextView   android: id=癅 + id/online_people_num”   android: layout_width=" 60 dp "   android: layout_height=" 40 dp "   android: layout_alignParentRight=" true "   android: layout_marginRight=" 10 dp”   android:重力=" center_horizontal | center_vertical”   android:文本=" 0/15 "   android:输入textColor=" # 000000 "/比;   & lt;/RelativeLayout>      

效果下图所示:

  

 Android仿QQ分组实现二级菜单展示

  

<强> 3。创建相应的数据对象

  

添加分组父菜单组

  

Group.class         包com.example.m1.QQGroup;      公开课组{   私人int mGroupImage;   私人字符串mGroupName;//分组名   私人字符串mGroupNum;//分组人数   私人布尔isDown;      mGroupName public组(int mGroupImage字符串,字符串mGroupNum) {   这一点。mGroupImage=mGroupImage;   这一点。mGroupName=mGroupName;   这一点。mGroupNum=mGroupNum;   }      public组(){   这一点。isDown=false;   }      公共空间changeDownStatus () {   isDown=! isDown;   }      公共布尔isDown () {   返回isDown;   }      公共空间着陆(布尔){   isDown=下来;   }      公共int getmGroupImage () {   返回mGroupImage;   }      公共空间setmGroupImage (int mGroupImage) {   这一点。mGroupImage=mGroupImage;   }      公共字符串getmGroupName () {   返回mGroupName;   }      公共空间setmGroupName(字符串mGroupName) {   这一点。mGroupName=mGroupName;   }      公共字符串getmGroupNum () {   返回mGroupNum;   }      公共空间setmGroupNum(字符串mGroupNum) {   这一点。mGroupNum=mGroupNum;   }   }

Android仿QQ分组实现二级菜单展示