ListView We use it all the time, but when we have more content in adapter we sometimes have no way to set up some components, for example:
Can see the story of Jingdong east of such a layout, this layout can be said that I currently see more content, each of its items include head, name, category, content, pictures, like, comment, share and like the avatar. After analyzing the layout, it is not difficult to find that, in addition to liking the Avatar part, the rest are well realized.
Then the following focus on this part of the Avatar how to achieve?
The first scenario: We can use the GridView to implement, the GridView and ListView use is the same, commonly known as the nine Sudoku arrangement, then we can arrange the GridView line nine pictures to display these heads, Just listview nested in the GridView a little bit of trouble, I did a, feel not good, there is want to ListView nested GridView can private me.
The second scenario: This is the dynamic load layout described in this article:
Very simply, we define a linerlayout linear layout in the ListView to store these heads, and look at the layout first:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "android:orientation=" vertical "android:layout_width=" match_parent "android:layout_height=" Match_pa Rent "> <linearlayout android:padding=" @dimen/small_space "android:orientation=" Horizontal "android:l" Ayout_width= "Match_parent" android:layout_height= "wrap_content" > <com.view.roundedimageview android:id = "@+id/iv_myspace_usericon" android:src= "@drawable/usericon" android:layout_width= "50DP" Android:layout_hei ght= "50DP"/> <textview android:id= "@+id/tv_myspace_username" android:layout_marginleft= "@dimen/middle_s
Pace "android:layout_gravity=" center_vertical "android:text=" Wang So-and-so "android:textsize=" @dimen/small_textsize "
android:layout_weight= "1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content"/> <textview android:id= "@+Id/tv_myspace_time "android:textcolor=" @color/normal_bar_futext_color "android:textsize=" @dimen/smallest_textsiz E "android:layout_gravity=" center_vertical "android:text=" 2015-8-26 17.46 "android:layout_width=" Wrap_conte NT "android:layout_height=" Wrap_content "/> </LinearLayout> <textview android:id=" @+id/tv_myspac E_content "android:paddingright=" @dimen/middle_space "android:paddingleft=" @dimen/middle_space "Android:paddin gbottom= "@dimen/middle_space" android:text= "by the room AH the Accounting Entry Accounting Law fleet commander to lose weight; get Jeffries to pay right away; the old card machine's argument; that's when you see the card." Android: Layout_width= "Match_parent" android:layout_height= "wrap_content"/> <imageview android:id= "@+id/iv_myspace_"
Image "Android:scaletype=" Fitxy "android:src=" @drawable/moren "android:paddingright=" @dimen/middle_space "
android:paddingleft= "@dimen/middle_space" android:layout_width= "match_parent" android:layout_height= "140DP"/> <linearlayout AndroiD:id= "@+id/ll_myspace_reply_icons" android:paddingtop= "@dimen/small_space" android:paddingright= "@dimen/middle_ Space "android:paddingleft=" @dimen/middle_space "android:orientation=" horizontal "android:layout_width=" Match_ Parent "android:layout_height=" wrap_content "> </LinearLayout> <linearlayout android:layout_margint op= "@dimen/small_space" android:paddingright= "@dimen/middle_space" android:paddingleft= "@dimen/middle_space" a ndroid:orientation= "Horizontal" android:layout_width= "Match_parent" android:layout_height= "wrap_content" > &L
T;imageview android:id= "@+id/iv_myspace_like" android:src= "@drawable/zan_icon" android:layout_width= "20DP" android:layout_height= "20DP"/> <imageview android:visibility= "Gone" android:id= "@+id/iv_myspace" _liked "android:src=" @drawable/wozaixianchang_dianzanxi "android:layout_width=" 20DP "Android:layout_heig ht= "20DP"/> <textvIew android:id= "@+id/tv_myspace_zan_count" android:layout_gravity= "center_vertical" android:text= "0" a Ndroid:textcolor= "@color/normal_bar_futext_color" android:layout_marginleft= "@dimen/small_space" Android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content"/> <imageview android:id= "@+id/iv_myspace_comm" Ent "android:layout_marginleft=" @dimen/middle_space "android:src=" @drawable/pinglun_icon "Android:layout_wi Dth= "20DP" android:layout_height= "20DP"/> <textview android:id= "@+id/tv_myspace_pinglun_count" and Roid:layout_gravity= "center_vertical" android:text= "0" android:textcolor= "@color/normal_bar_futext_color" a ndroid:layout_marginleft= "@dimen/small_space" android:layout_width= "wrap_content" android:layout_height= "Wrap_co Ntent "/> </LinearLayout> </LinearLayout> <linearlayout android:id=" @+id/ll_myspace_reply_i Cons "Android:paddingtop= "@dimen/small_space" android:paddingright= "@dimen/middle_space" android:paddingleft= "@dimen/middle_space" android:orientation= "Horizontal" android:layout_width= "Match_parent" android:layout_height= "Wrap_content" > &
Lt;/linearlayout>
The above linearlayout is put these head, the other is not much said, the following we see how to give our adapter inside add these heads
Linearlayout.layoutparams params = new Linearlayout.layoutparams (m);
Params.setmargins (8, 0, 8, 0);
Roundedimageview.setlayoutparams (params);
Roundedimageview.setscaletype (ImageView.ScaleType.FIT_XY);
if (! "". Equals (Replyurl.get (m)) && Replyurl.get (m)!= null) {
imageloader.getinstance (). DisplayImage ( Replyurl.get (M), Roundedimageview);
else {
roundedimageview.setimagedrawable (context.getresources (). getdrawable (R.drawable.usericon));
}
if (m = = count) {
roundedimageview.setimagedrawable (context.getresources (). Getdrawable ( R.drawable.wozaixianchangxiangqing_shenglve));
} else {
Holder.llReplyIcons.addView (Roundedimageview);
}
We first define a layoutparams, set some attributes of the avatar picture, including size, margins, and ScaleType, and then set it to our ImageView, and finally Holder.llReplyIcons.addView ( Roundedimageview); Adding a child layout is OK. Jing Dong This is fixed the number of head, and I write is based on the width of the phone screen to add a head:
WindowManager wm = (WindowManager) context.getsystemservice (context.window_service);
int width = Wm.getdefaultdisplay (). getwidth ();
int count = width/116;
Count is the avatar that can be added, and when I equals our count in view, we can display it with the last ellipsis picture.
Before someone in the group asked me this avatar click to jump to the personal homepage How to achieve, think about it, is not able to use the mobile phone to touch the coordinates to calculate the coordinates located in the first few avatar, think that more trouble. We can add the sub-layout avatar, we will give this child layout set Click event, you can, look at the code:
for (int m = 0; m < replyurl.size (); m++) {Roundedimageview Roundedimageview = new Roundedimageview (context);
Final int finalm = m;
Roundedimageview.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (view view) { if (story.getreply_user_id (). Get (Finalm)!= null) {Intent Intent = new Intent (context, MYSTORYACTIVITY.C
LASS);
Intent.putextra ("userid", story.getreply_user_id (). Get (Finalm));
Intent.putextra ("User_iconurl", Story.getreply_user_icon_url (). Get (Finalm));
Intent.putextra ("username", Story.getreply_user_name (). Get (Finalm));
Intent.putextra ("Flag", "others");
Context.startactivity (Intent);
else {Intent Intent = new Intent (context, storyfavoriteacitvity.class);
Intent.putextra ("storyID", Story.getid ());
Context.startactivity (Intent);
}
}
}); Linearlayout.layoutparams params = new LinearLayout.
Layoutparams (100, 100);
Params.setmargins (8, 0, 8, 0);
Roundedimageview.setlayoutparams (params);
Roundedimageview.setscaletype (ImageView.ScaleType.FIT_XY); if (! "". Equals (Replyurl.get (m)) && Replyurl.get (m)!= null) {imageloader.getinstance (). DisplayImage (Replyurl.get (M
), Roundedimageview);
else {roundedimageview.setimagedrawable (Context.getresources (). getdrawable (R.drawable.usericon)); } if (m = = count) {roundedimageview.setimagedrawable (Context.getresources (). Getdrawable (R.drawable.wozaixian
Changxiangqing_shenglve));
else {Holder.llReplyIcons.addView (Roundedimageview);
}
}
This code is all included, some of which are the parameters of the server returned, are real data. So you can click on the avatar jump.
So the final look at my own implementation of the interface is not the same as Jingdong?
How about it?