兴趣标签的实现

作者: 莫语莫雨 | 来源:发表于2018-11-30 11:25 被阅读0次
如今的APP中,对用户的兴趣,爱好等还是比较看重的,因为可以通过这些来向用户推送个性化的内容,大部分的APP中,都会涉及类似下面的内容,来让用户选择,来了解用户的兴趣和习惯. image.png

今天,我们就来以上面这张图为原型,来实现这样的功能界面

实现步骤

1.界面分析

看到这个界面,我们大概可以分为三部分,标题我们可以使用TextView就可以轻松实现,中间可以使用RecycleView的多条目展示来进行展示,而下面的提交按钮,则可以用Button来实现,话不多说,下面开始干吧! image.png
2.界面布局搭建

首先将界面的大致布局编写出来

<?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_parent">

    <TextView
            android:layout_gravity="center_horizontal"
            android:textStyle="bold"
            android:layout_margin="20dp"
            android:textSize="18sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="选择您感兴趣的标签"/>

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/label_list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    <Button
            android:id="@+id/commit"
            android:layout_margin="20dp"
            android:textSize="16sp"
            android:textColor="#fff"
            android:background="@drawable/shape_commit_bg"
            android:text="提 交"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
</LinearLayout>
image.png

3.多条目布局分析

通过对多条目的分析,我们可以得出,这个列表其实只有两种组成,一个TextView和RecycleView image.png
4.条目布局的编写 image.png
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:padding="10dp"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">

    <TextView
            android:text="男生推荐"
            android:textSize="16sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    <androidx.recyclerview.widget.RecyclerView
            android:padding="10dp"
            android:id="@+id/label"
            tools:listitem="@layout/item_label"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:spanCount="4"
            tools:layoutManager="GridLayoutManager"
            tools:itemCount="7"/>
</LinearLayout>
image.png
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_gravity="center"
              android:layout_margin="5dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">

    <TextView
            android:paddingBottom="3dp"
            android:paddingTop="3dp"
            android:paddingRight="10dp"
            android:paddingLeft="10dp"
            android:background="@drawable/shape_label_bg"
            android:text="玄幻"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
</LinearLayout>

5.主布局及适配器编写

class XingQuActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_xingqu)

        label_list.layoutManager = LinearLayoutManager(this)
        label_list.adapter = LabelAdapter()
    }

    class LabelAdapter : RecyclerView.Adapter<LabelAdapter.LabelViewHolder>() {
        lateinit var context: Context
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LabelViewHolder {
            context = parent.context
            val view = LayoutInflater.from(context).inflate(R.layout.item_labels_layout, parent, false)
            return LabelViewHolder(view)
        }

        override fun getItemCount(): Int {
            return 3
        }

        override fun onBindViewHolder(holder: LabelViewHolder, position: Int) {
            holder.labelList.layoutManager = GridLayoutManager(context,4)
            holder.labelList.adapter = LabelsAdapter()
        }

        class LabelViewHolder(view: View) :RecyclerView.ViewHolder(view){
            val labelList = view.findViewById<RecyclerView>(R.id.label)
        }

        class LabelsAdapter : RecyclerView.Adapter<LabelsAdapter.LabelsViewHolder>() {
            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LabelsViewHolder {
                val view = LayoutInflater.from(parent.context).inflate(R.layout.item_label, parent, false)
                return LabelsViewHolder(view)
            }

            override fun getItemCount(): Int {
                return 5
            }

            override fun onBindViewHolder(holder: LabelsViewHolder, position: Int) {
            }


            class LabelsViewHolder(view: View) :RecyclerView.ViewHolder(view){
            }

        }
    }
}

6.最终效果
这里只是实现功能,界面大家可以根据UI的设计图进行修改优化


Screenshot_2018-11-30-11-23-45-038_com.clb.js.png

相关文章

  • 兴趣标签的实现

    今天,我们就来以上面这张图为原型,来实现这样的功能界面 实现步骤 1.界面分析 首先将界面的大致布局编写出来 3....

  • UICollectionView实现的标签选择器

    近来,在项目中需要实现一个类似兴趣标签的选择器。由于标签的文字长度不定,所以标签的显示长度就不定。为了实现效果,就...

  • UIWebView与JS简单交互(删除标签和获取某个标签的内容)

    一直以来都对获取网页中的某个标签的内容感兴趣,很好奇怎么实现获取到网页中某个标签,今天自己开始研究一下,如何去获取...

  • day11

    Servlet JSP 自定义标签 开发步骤 实现标签类,实现标签接口集成半成品的支持类更加方便 登记标签类在tl...

  • 热门标签,流式标签的实现

    废话不多说,先直接上最终的效果图(完整代码链接在底部)flexboxLayout.png 注:“小米超神”是在代码...

  • Markdown第一天-part1换行

    换行的两种方法: 方法1:标签


    特点: 单个标签可以实现换行, 多个标签可以实现多...

  • git 打标签

    显示所有标签: 只对某一类型标签感兴趣: 打标签 显示具体标签信息: 删除本地标签 删除远程标签 推送标签到远程分支

  • 自定义标签FlowTagLayout

    为什么写这个库? 项目中有时候会有这样的需求,比如兴趣爱好的选择、搜索历史标签等,自带的Android控件实现起来...

  • 【问题收集】UICollectionView:设置content

    场景 上面的标签栏是使用 UICollectionView 实现的,需要实现的效果是: 规则:上面的标签栏,选中的...

  • 实现background-size: cover的几种方法

    background实现 img标签实现 svg实现 codepen 中自己试试吧

网友评论

    本文标题:兴趣标签的实现

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