Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

android - Listview with different layout inflation for each row

I'm fairly new to designing UIs in Android (And fairly new to Android development as well). I'm currently developing an Android application that looks a lot like Google+'s "All Circles" page, and Facebook's user home, where you get to see contents shared by your friends.

To make things clearer, please take a look at the following screenshot that's taken from Google+'s Android application:

enter image description here

As you can see, Paul Harper's post is in a little Frame, and "Android and me"'s post is in another. And the more you scroll downwards, the more shared stuff you'll see, each in its own "Frame".

I'm really not sure how to achieve this result(I'm sure that it involves a ListView component), so could anyone please tell me about the UI components that I should be using to do it?

Thanks a ton.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should have a look at the video in the link.

http://www.youtube.com/watch?v=wDBM6wVEO70

private static final int TYPE_ITEM1 = 0;
private static final int TYPE_ITEM2 = 1;
private static final int TYPE_ITEM3 = 2;    

int type;

@Override
public int getItemViewType(int position) {

    if (position== 0){
        type = TYPE_ITEM1;
    } else if  (position == 1){
        type = TYPE_ITEM2;
    }
    return type;
}


@Override  
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
LayoutInflater inflater = null;
int type = getItemViewType(position);
   if (row  == null) {
    if (type == TYPE_ITEM1) {
                 //infalte layout of type1
      }
    if (type == TYPE_ITEM2) {
                 //infalte layout of type2
    }  else {
                 //infalte layout of normaltype
 }
} 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...