Giter Club home page Giter Club logo

labellayout's Introduction

LabelLayout

License Download

自动换行控件

预览

center

left

1.用法

Android Studio使用依赖:

compile 'cn.kevin:labellayout:1.0.0'

2.功能

  • 自动换行,可实现,对齐方式: 左、中、右。

3.属性

自定义属性 含义
label_gravity 对齐方式, 居左:left,局中:center,居右:right

4.代码演示 也可参考demo中的代码

1.在布局文件中加入LabelLayout

<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="wrap_content"
    android:orientation="vertical">
    <cn.kevin.labellayout.LabelLayout
        android:id="@+id/label_layout"
        android:layout_marginLeft="40dp"
        app:label_gravity="center"
        android:layout_marginRight="40dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

2.定义自己的标签View

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:textSize="12sp"
    android:background="@drawable/corner_shape"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="12dp"
    android:paddingTop="5dp"
    android:textColor="#FFFFFF"
    android:paddingRight="12dp"
    android:maxLines="1"
    android:ellipsize="end"
    android:layout_marginLeft="6dp"
    android:layout_marginTop="4dp"
    android:layout_marginRight="6dp"
    android:layout_marginBottom="4dp"
    android:paddingBottom="5dp">
</TextView>

3.实现LabelAdapter

class TextLabelAdapter extends LabelAdapter<String> {
        public TextLabelAdapter(List<String> models) {
            super(models);
        }
        @Override
        public void onDataSet(View labelView, String item) {
            ((TextView)labelView).setText(item);
        }

        @Override
        public View getLabelView(ViewGroup parent) {
            return LayoutInflater.from(DemoActivity.this).inflate(R.layout.label, parent, false);
        }
    }

4.设置数据适配器

        labelLayout = (LabelLayout) findViewById(R.id.label_layout);
        List<String> list = new ArrayList<>();
        list.add("升职加薪");
        list.add("当上总经理");
        list.add("出任ceo");
        list.add("迎娶白富美");
        list.add("走上人生巅峰,想想还有点小激动");
        TextLabelAdapter adapter = new TextLabelAdapter(list);
        labelLayout.setAdapter(adapter);

labellayout's People

Contributors

kevin-mob avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.