Android中列表嵌套列表实现

作者: 丶尐東謌丶 | 来源:发表于2016-10-27 22:51 被阅读0次

前言:

      我是一只android菜鸟,做开发时间也不长,第一次写文章,没有别的意思,就是为了记住自己曾经遇到过的坑,方便记忆,也为了方便更多的朋友;

话不多说,看需求:

需求是这样的,

看需求

整个页面是一个表,而每个item又是一个列表,并且还有个标题,刚看到需求立马想到使用列表的多种行视图,但是那样搞的话太复杂了,后来拆分了一下,

第一步:

外边的列表item可以只添加一个标题,这样:

xml布局中这样写:

 android:layout_width="match_parent"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_marginTop="@dimen/w10dp"

android:layout_marginBottom="@dimen/w10dp"

android:layout_marginLeft="@dimen/w20dp"

android:layout_marginRight="@dimen/w20dp"

app:cardBackgroundColor="@color/white"

app:cardCornerRadius="@dimen/w10dp"

app:cardElevation="@dimen/w10dp"

android:layout_height="wrap_content">

android:id="@+id/ll_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@mipmap/day_bg"

android:padding="@dimen/w10dp"

android:layout_marginTop="@dimen/w24dp"

android:layout_marginLeft="@dimen/w24dp"

android:textColor="@color/white"

android:textSize="@dimen/w24dp"

android:text="2016年10月26日"/>

android:layout_width="match_parent"

android:background="@color/bg"

android:layout_marginTop="@dimen/w10dp"

android:layout_marginLeft="@dimen/w30dp"

android:layout_marginRight="@dimen/w30dp"

android:layout_height="@dimen/w1dp"/>


第二步:

在Adapter中:  动态的为每个item添加数据,我这暂时没有真实数据,暂且用假数据代替,总之先出来效果再说

/**

* Created by 321 on 2016/10/27.

*/

public classRecorAdapter  extends    RecyclerView.Adapter {

private   Context   mContext;

private   List>dates;

public    RecorAdapter(Context mContext,List> dates) {

this.mContext = mContext;

this.dates= dates;

}

@Override

public   MyViewHolder   onCreateViewHolder(ViewGroup parent, intviewType) {

View view = LayoutInflater.from(mContext).inflate(R.layout.item_recor_outer,parent,false);

return newMyViewHolder(view);

}

@Override

public void    onBindViewHolder(MyViewHolder holder, intposition) {

for(inti =0;i <=2;i++){

View item = LayoutInflater.from(mContext).inflate(R.layout.item_recor,null);

intwidth = LinearLayout.LayoutParams.WRAP_CONTENT;

intheight = LinearLayout.LayoutParams.WRAP_CONTENT;

LinearLayout.LayoutParams params =newLinearLayout.LayoutParams(width,height);

item.setLayoutParams(params);

holder.ll_layout.addView(item);

if(i ==0){

item.findViewById(R.id.view_1).setVisibility(View.INVISIBLE);

}

if(i ==4){

item.findViewById(R.id.view_2).setVisibility(View.INVISIBLE);

}

}

}

@Override

public intgetItemCount() {

returndates.size();

}

class     MyViewHolder   extends    RecyclerView.ViewHolder{

LinearLayoutll_layout;

public    MyViewHolder(View itemView) {

super(itemView);

ll_layout= (LinearLayout) itemView.findViewById(R.id.ll_layout);

}

}

}

主要是填充了这个布局:

```

View item = LayoutInflater.from(mContext).inflate(R.layout.item_recor,null);

```

xml中是这样的:

```

android:layout_width="match_parent"

android:layout_height="@dimen/w170dp">

android:id="@+id/view_1"

android:layout_width="1dp"

android:layout_height="@dimen/w31dp"

android:layout_marginLeft="@dimen/w34dp"

android:background="@color/colorblue"/>

android:id="@+id/image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="@dimen/w30dp"

android:layout_marginTop="@dimen/w30dp"

android:src="@mipmap/circle"/>

android:id="@+id/view_2"

android:layout_width="1dp"

android:layout_height="@dimen/w139dp"

android:layout_below="@id/view_1"

android:layout_marginLeft="@dimen/w34dp"

android:background="@color/colorblue"/>

android:layout_width="match_parent"

android:layout_height="@dimen/w170dp"

android:layout_marginLeft="@dimen/w24dp"

android:layout_marginRight="@dimen/w30dp"

android:layout_toRightOf="@id/image"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_marginTop="@dimen/w27dp"

android:layout_height="wrap_content">

android:id="@+id/tv_num"

style="@style/recor_style"

android:text="团号:"

android:textColor="@color/colorAccent"/>

style="@style/recor_style"

android:layout_marginLeft="@dimen/w30dp"

android:layout_toRightOf="@id/tv_num"

android:text="3685"

android:textColor="@color/colorAccent"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_marginRight="@dimen/w6dp"

android:text="11:00-14:00"

android:textColor="@color/color_7e8082"

android:textSize="@dimen/w24dp"/>

android:layout_width="match_parent"

android:layout_marginTop="@dimen/w12dp"

android:layout_height="wrap_content">

android:id="@+id/tv_num2"

style="@style/recor_style"

android:text="团名:"

android:textColor="@color/color_535353"/>

style="@style/recor_style"

android:layout_marginLeft="@dimen/w30dp"

android:layout_toRightOf="@id/tv_num2"

android:textColor="@color/color_535353"

android:text="中央视察团"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="@dimen/w12dp">

android:id="@+id/tv_num3"

style="@style/recor_style"

android:textColor="@color/color_535353"

android:text="人数:"/>

style="@style/recor_style"

android:layout_marginLeft="@dimen/w30dp"

android:textColor="@color/color_535353"

android:layout_toRightOf="@id/tv_num3"

android:text="85"/>

android:layout_width="match_parent"

android:layout_height="@dimen/w1dp"

android:layout_alignParentBottom="true"

android:layout_marginLeft="@dimen/w56dp"

android:layout_marginRight="@dimen/w30dp"

android:background="@color/bg"/>

```

时间轴:

这个时间轴一开始不知道怎么做,百度了一下,好多人还要自定义View什么的,太麻烦了,直接使用布局,直接搞定,不就是两条填充高度的线中间加一个原点嘛

android:id="@+id/view_1"

android:layout_width="1dp"

android:layout_height="@dimen/w31dp"

android:layout_marginLeft="@dimen/w34dp"

android:background="@color/colorblue"/>

android:id="@+id/image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="@dimen/w30dp"

android:layout_marginTop="@dimen/w30dp"

android:src="@mipmap/circle"/>

android:id="@+id/view_2"

android:layout_width="1dp"

android:layout_height="@dimen/w139dp"

android:layout_below="@id/view_1"

android:layout_marginLeft="@dimen/w34dp"

android:background="@color/colorblue"/>

activity中的代码就没有比哟啊贴出来了,小学生都会,

跟大神学的,写在最后:

我不是大神,我只是小菜鸟,文采不好,技术一般,写文章就是为自己也为他人提供个方便,希望可以帮助需要的人


相关文章

  • Android中列表嵌套列表实现

    前言: 我是一只android菜鸟,做开发时间也不长,第一次写文章,没有别的意思,就是为了记住自己曾经遇到过的坑...

  • Android RecyclerView嵌套的滑动冲突问题

    前言 在Android的开发中,不可避免的需要用到列表嵌套列表的需要,如recycleView嵌套recylerV...

  • python(7):字典(2)

    1.嵌套 将一系列字典存贮再列表中,或将列表作为值存贮在字典中,称为嵌套。可以在列表中嵌套字典,字典中嵌套列表,字...

  • markdown test

    一级标题 二级标题 三级标题 嵌套列表嵌套列表嵌套列表嵌套列表嵌套列表嵌套列表 无序列表 无序列表 有序列表1 有...

  • 一 -18 python (基础)列表的镶嵌

    列表嵌套 类似while循环的嵌套,列表也是支持嵌套的 一个列表中的元素又是一个列表,那么这就是列表的嵌套叫做二维...

  • Python:嵌套

    1.在列表中嵌套字典 字典列表:将字典存储在列表中 2.在字典中嵌套列表 将列表存储在字典中每当需要在字典中讲一个...

  • 用HTML来写列表

    考虑用html如何实现以下列表: 要实现的是有序列表和无序列表以及嵌套列表的结合 有序列表: 定义和用法: ...

  • 栈-N385-迷你语法分析器

    题目 概述:给定一个用字符串表示的整数的嵌套列表,列表中的每个元素只能是整数或者整数嵌套列表,实现一个解析它的语法...

  • HTML第三天

    列表标签 无序列表标签:ul 列表项1 列表项2 列表项3 ...... 中只能嵌套 ,直接在 标记中...

  • Python基础_04:列表(2019-1-13)

    列表 列表嵌套

网友评论

    本文标题:Android中列表嵌套列表实现

    本文链接:https://www.haomeiwen.com/subject/rayzyttx.html