【问题标题】:Listview with different layout inflation for each row每行具有不同布局膨胀的列表视图
【发布时间】:2013-03-29 15:01:14
【问题描述】:

我对在 Android 中设计 UI 还很陌生(对 Android 开发也很陌生)。我目前正在开发一个 Android 应用程序,它看起来很像 Google+ 的“All Circles”页面和 Facebook 的用户主页,您可以在其中查看朋友分享的内容。

为了让事情更清楚,请查看以下截取自 Google+ 的 Android 应用程序的屏幕截图:

如您所见,Paul Harper 的帖子在一个小框架中,而“Android and me”的帖子在另一个框架中。向下滚动的次数越多,您看到的共享内容就越多,每个都在自己的“框架”中。

我真的不确定如何实现这个结果(我确定它涉及一个 ListView 组件),所以谁能告诉我应该使用哪些 UI 组件来实现它?

非常感谢。

【问题讨论】:

    标签: android user-interface android-listview


    【解决方案1】:

    您应该看看链接中的视频。

    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 类型;

    @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
     }
    } 
    

    【讨论】:

    • 非常感谢您的帮助。这是您提供的 youtube 链接中的代码:
    【解决方案2】:

    你是对的。对于列表,您需要查找的关键字是“ListView”、“ListFragment”、“ListActivity”。要为您的列表(项目)提供自定义外观,您需要为列表行定义自己的布局,然后可以包含多个子视图。要使用内容填充行(及其子视图),您需要定义您在列表中设置的自定义适配器。寻找(例如)“ArrayAdapter”、“SimpleCursorAdapter”。

    尝试在 Google 上搜索“android 列表自定义布局”和“android 列表适配器”。

    最好的问候, 塞巴斯蒂安

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多