labelview标签列表控件的使用介绍

标签列表控件的使用介绍支持点击事件监听step1: D:\workspace\LabelViewDemoTwo\app\src\main\res\values\strings.xml<resources> <string name="app_name">LabelViewDemo</string> <item name="tag_key_data" type="id" /> <item name="tag_key_posit
摘要由CSDN通过智能技术生成

标签列表控件的使用介绍

支持点击事件监听

step1: D:\workspace\LabelViewDemoTwo\app\src\main\res\values\strings.xml

<resources>
    <string name="app_name">LabelViewDemo</string>
    <item name="tag_key_data" type="id" />
    <item name="tag_key_position" type="id" />
</resources>

step2: D:\workspace\LabelViewDemoTwo\app\src\main\res\values\attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="LabelsView">
        <attr name="selectType" format="enum">
            <enum name="NONE" value="1" />
            <enum name="SINGLE" value="2" />
            <enum name="SINGLE_IRREVOCABLY" value="3" />
            <enum name="MULTI" value="4" />
        </attr>

        <attr name="labelGravity">
            <!-- Push object to the top of its container, not changing its size. -->
            <flag name="top" value="0x30" />
            <!-- Push object to the bottom of its container, not changing its size. -->
            <flag name="bottom" value="0x50" />
            <!-- Push object to the left of its container, not changing its size. -->
            <flag name="left" value="0x03" />
            <!-- Push object to the right of its container, not changing its size. -->
            <flag name="right" value="0x05" />
            <!-- Place object in the vertical center of its container, not changing its size. -->
            <flag name="center_vertical" value="0x10" />
            <!-- Grow the vertical size of the object if needed so it completely fills its container. -->
            <flag name="fill_vertical" value="0x70" />
            <!-- Place object in the horizontal center of its container, not changing its size. -->
            <flag name="center_horizontal" value="0x01" />
            <!-- Grow the horizontal size of the object if needed so it completely fills its container. -->
            <flag name="fill_horizontal" value="0x07" />
            <!-- Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. -->
            <flag name="center" value="0x11" />
            <!-- Grow the horizontal and vertical size of the object if needed so it completely fills its container. -->
            <flag name="fill" value="0x77" />
            <!-- Additional option that can be set to have the top and/or bottom edges of
                 the child clipped to its container's bounds.
                 The clip will be based on the vertical gravity: a top gravity will clip the bottom
                 edge, a bottom gravity will clip the top edge, and neither will clip both edges. -->
            <flag name="clip_vertical" value="0x80" />
            <!-- Additional option that can be set to have the left and/or right edges of
                 the child clipped to its container's bounds.
                 The clip will be based on the horizontal gravity: a left gravity will clip the right
                 edge, a right gravity will clip the left edge, and neither will clip both edges. -->
            <flag name="clip_horizontal" value="0x08" />
            <!-- Push object to the beginning of its container, not changing its size. -->
            <flag name="start" value="0x00800003" />
            <!-- Push object to the end of its container, not changing its size. -->
            <flag name="end" value="0x00800005" />
        </attr>

        <attr name="maxSelect" format="integer" />
        <attr name="minSelect" format="integer" />
        <attr name="maxLines" format="integer" />
        <attr name="maxColumns" format="integer" />
        <attr name="isIndicator" format="boolean" />
        <attr name="labelTextColor" format="reference|color" />
        <attr name="labelTextSize" format="dimension" />
        <attr name="labelTextWidth" format="dimension">
            <enum name="fill_parent" value="-1" />
            <enum name="match_parent" value="-1" />
            <enum name="wrap_content" value="-2" />
        </attr>
        <attr name="labelTextHeight" format="dimension">
            <enum name="fill_parent" value="-1" />
            <enum name="match_parent" value="-1" />
            <enum name="wrap_content" value="-2" />
        </attr>
        <attr name="labelTextPadding" format="dimension" />
        <attr name="labelTextPaddingLeft" format="dimension" />
        <attr name="labelTextPaddingTop" format="dimension" />
        <attr name="labelTextPaddingRight" format="dimension" />
        <attr name="labelTextPaddingBottom" format="dimension" />
        <attr name="lineMargin" format="dimension" />
        <attr name="wordMargin" format="dimension" />
        <attr name="labelBackground" format="reference|color" />
        <attr name="singleLine" format="boolean" />
        <attr name="isTextBold" format="boolean" />
    </declare-styleable>
</resources>

step3: D:\workspace\LabelViewDemoTwo\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#cccccc"
    android:orientation="vertical">

    <com.example.labelviewdemotwo.LabelsView
        android:id="@+id/btnLabels"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:minHeight="25dp"
        android:padding="5dp"
        app:isIndicator="true"
        app:labelBackground="#433f3f"
        app:labelTextColor="#ffffff"
        app:labelTextPaddingBottom="5dp"
        app:labelTextPaddingLeft="10dp"
        app:labelTextPaddingRight="10dp"
        app:labelTextPaddingTop="5dp"
        app:labelTextSize="14sp"
        app:lineMargin="10dp"
        app:selectType="SINGLE"
        app:wordMargin="10dp" />

</LinearLayout>

step4: D:\workspace\LabelViewDemoTwo\app\src\main\res\drawable\default_label_bg.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:width="1dp"
        android:color="#656565" />
    <corners android:radius="5dp" />
    <solid android:color="@android:color/white" />
</shape>

step5: D:\workspace\LabelViewDemoTwo\app\src\main\java\com\example\labelviewdemotwo\TestBean.java

package com.example.labelviewdemotwo;

/**
 * Depiction:
 * Author:lry
 * Date:2018/1/20
 */

public class TestBean {
   

    private String name;
    private int id;

    public TestBean(String name, int id) {
   
        this.name = name;
        this.id = id;
    }

    public String getName() {
   
        return name;
    }

    public void setName(String name) {
   
        this.name = name;
    }

    public int getId() {
   
        return id;
    }

    public void setId(int id) {
   
        this.id = id;
    }

    @Override
    public String toString() {
   
        return "TestBean{" +
                "name='" + name + '\'' +
                ", id=" + id +
                '}';
    }
}

step6: D:\workspace\LabelViewDemoTwo\app\src\main\java\com\example\labelviewdemotwo\MainActivity.java

package com.example.labelviewdemotwo;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
   
    private LabelsView labelsView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        labelsView = findViewById(R.id.btnLabels);
        ArrayList<TestBean> testList = new ArrayList<>();
        testList.add(new TestBean("Android", 1));
        testList.add(new TestBean("IOS", 2));
        testList.add(new TestBean("前端", 3));
        testList.add(new TestBean("后台", 4));
        testList.add(new TestBean("微信开发", 5));
        testList.add
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: LabelView 技术是一种用于 Android 应用程序中的自定义视图技术。它允许在一个视图的周围添加标签,以突出显示视图的重要性或其他信息。LabelView 可以轻松地添加到布局中,并可以自定义颜色、位置和文本等属性。这种技术可以应用于各种场景,例如在列表项中添加标记、突出显示关键信息等。使用 LabelView 技术可以增强应用程序的用户体验,并使界面更加直观和易于理解。 ### 回答2: labelView 技术是一种用来在视图层级中添加标签或标记的技术。它可以在一个视图上方或下方叠加一个带有文本或图标的小标签,以便更好地传达信息或提供额外的功能。 使用 labelView 技术可以提升用户界面的可用性和可理解性。通过为视图添加标签,用户可以更容易地识别和理解视图的用途或功能。例如,在一个图像展示应用中,我们可以使用 labelView 技术在每个图像的右上角添加一个标签,标识图像的来源或类别。 此外,labelView 技术还可以用来提供额外的交互功能。标签上可以添加按钮、交互链接或其他交互元素,以便用户能够直接从标签上执行某些操作。例如,在一个电子商务应用中,我们可以在产品的标签上添加一个按钮,用于将该产品添加到购物车或进行其他操作。 在实现 labelView 技术时,我们可以使用各种技术和框架。例如,在 Android 平台上,我们可以使用 Android 的自定义视图或第三方库来创建 labelView。在 iOS 平台上,我们可以使用 iOS 的自定义视图或第三方库来实现。 总而言之,labelView 技术是一种在视图层级中添加标签或标记的技术,它可以提升用户界面的可用性和可理解性,并为用户提供额外的交互功能。通过适当使用 labelView 技术,我们可以增强应用程序的用户体验。 ### 回答3: labelView 技术是一种用于显示标签的技术。标签是用来标识和描述数据的元素,通常用于在界面上显示数据的名称、类别或者其他相关信息。而 labelView 技术则是一种让标签显示更加美观和易读的技术。 labelView 技术可以通过改变标签的字体、字号、颜色、背景等样式属性来使其更加吸引人的目光。通过采用合适的字体和颜色搭配,可以让标签更加清晰易读,增强用户对标签的关注和辨识度。 此外,labelView 技术还可以通过设置标签的布局、对齐方式、间距等来使其在界面中的位置更加恰当和整齐。通过将标签与其他元素进行合理的排列和组合,可以提升整体界面的美观度和可用性。 labelView 技术还可以根据需要对标签进行动态的内容更新和交互操作。通过编程方式,可以实现实时更新标签的内容,使其显示最新的信息。同时,还可以为标签添加交互功能,如点击事件、长按事件等,以便用户与标签进行交互操作,提供更加灵活和便捷的使用体验。 总之,labelView 技术是一种用于美化和优化标签显示的技术,可以提升标签的吸引力、易读性和布局效果,增强用户对标签的关注和使用体验。在各种应用场景中,labelView 技术都有着广泛的应用和重要的作用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值