自定义适配器具有多个子项的项目清单? [英] Custom adapter for a list of items that have multiple child items?

查看:155
本文介绍了自定义适配器具有多个子项的项目清单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何,我会去写一个适配器此布局。我开始想制造使用线性和相对布局的列表,这样,每个项目都有子项水平对齐相对于彼此。这里是布局文件和视图的屏幕截图。

我知道如何编写简单的列表视图和适配器。但只是想知道我怎么可以得到更复杂的列表超过满手的孩子列表中的项目。

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / trade_scenario_linear_main
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:后台=#8a929d>
    < RelativeLayout的
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =机器人:ATTR /列表preferredItemHeight
        机器人:填充=6dip
        机器人:后台=#e8e7e2>

        < ImageView的
            机器人:ID =@ + ID /阿凡达
            机器人:layout_width =65dp
            机器人:layout_height =65dp
            机器人:layout_alignParentBottom =真
            机器人:layout_alignParentTop =真
            机器人:contentDescription =TODO
            机器人:SRC =@可绘制/ avatar_temp/>

        <的TextView
            机器人:ID =@ + ID /用户名
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentTop =真
            机器人:layout_alignWithParentIfMissing =真
            机器人:layout_toRightOf =@ ID /阿凡达
            机器人:文本=牧羊人
            机器人:文字颜色=#ED872D
            机器人:TEXTSIZE =12SP/>

        < ImageView的
            机器人:ID =@ + ID / clock_icon
            机器人:layout_width =16DP
            机器人:layout_height =16DP
            机器人:layout_marginLeft =90dp
            机器人:layout_gravity =右
            机器人:layout_toRightOf =@用户名/用户名
            机器人:SRC =@可绘制/ clock_icon/>
        <的TextView
            机器人:ID =@ + ID / clock_data
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_toRightOf =@ ID / clock_icon
            机器人:TEXTSIZE =14sp
            机器人:文本=22H 30分钟/>

        < ImageView的
            机器人:ID =@ + ID / comments_icon
            机器人:layout_width =16DP
            机器人:layout_height =16DP
            机器人:layout_alignParentBottom =真
            机器人:layout_toRightOf =@ ID /阿凡达
            机器人:SRC =@可绘制/发表评论/>

        <的TextView
            机器人:ID =@ + ID / comments_num
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =26dip
            机器人:layout_alignParentBottom =真
            机器人:layout_alignTop =@ + ID / comments_icon
            机器人:layout_toRightOf =@ ID / comments_icon
            机器人:ellipsize =金字招牌
            机器人:单线=真
            机器人:文本=14
            机器人:TEXTSIZE =12SP/>

    < / RelativeLayout的>
< / LinearLayout中>
 

解决方案

创建自定义listiew,也可以创建自定义的接口,这样的 按照Totorials,帮助你: 自定义列表视图 也按照以上essier <一href="http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92"相对=nofollow>列表视图

How would i go about writing an adapter for this Layout. I started out wanting to making a list using linear and relative layout, so that each list item has child items align horizontally relative to each other. Here is the layout file and the screenshot of the view.

I understand how to write simple list views and adapters. But just wondering how i can get to more complex lists with more than hand full of child list items.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/trade_scenario_linear_main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#8a929d">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:padding="6dip"
        android:background="#e8e7e2">

        <ImageView
            android:id="@+id/avatar"
            android:layout_width="65dp"
            android:layout_height="65dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:contentDescription="TODO"
            android:src="@drawable/avatar_temp" />

        <TextView
            android:id="@+id/username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignWithParentIfMissing="true"
            android:layout_toRightOf="@id/avatar"
            android:text="Shepherd"
            android:textColor="#ED872D"
            android:textSize="12sp" />

        <ImageView
            android:id="@+id/clock_icon"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_marginLeft="90dp"
            android:layout_gravity="right"
            android:layout_toRightOf="@id/username"
            android:src="@drawable/clock_icon" />
        <TextView
            android:id="@+id/clock_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/clock_icon"
            android:textSize="14sp"
            android:text="22H 30mins"/>

        <ImageView
            android:id="@+id/comments_icon"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@id/avatar"
            android:src="@drawable/comment" />

        <TextView
            android:id="@+id/comments_num"
            android:layout_width="wrap_content"
            android:layout_height="26dip"
            android:layout_alignParentBottom="true"
            android:layout_alignTop="@+id/comments_icon"
            android:layout_toRightOf="@id/comments_icon"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:text="14"
            android:textSize="12sp" />

    </RelativeLayout> 
</LinearLayout>

解决方案

Create custom listiew and also create the custom adapter, like that follow that Totorials that help you: Custom Listviews also follow that more essier List View

这篇关于自定义适配器具有多个子项的项目清单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆