Code Monkey home page Code Monkey logo

ybflowlayout's Introduction

YbFlowLayout

介绍

一个支持对齐方式,适配器,设置显示行数的流式布局组件

安装教程

导入依赖

implementation 'com.gitee.bigyb:yb-flow-layout:1.0'

使用说明

布局编写

<!--  app:tag_gravity="center"   设置对齐方式,默认左对齐-->

<com.example.ybflowlayout.YbFlowLayout
        app:tag_gravity="center"   
        android:id="@+id/ybFlow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>



编写适配器


    //继承 YbFlowLayout.FlowAdapter  泛型为item的数据类型
   public class MyAdapter extends YbFlowLayout.FlowAdapter<String> {
    public MyAdapter(List<String> mDatas) {
        //第二个参数请设置 item 的对应布局文件
        super(mDatas, R.layout.layout_item);
    }
    
     /**
     * @param mView  返回要加载的item view
     * @param pos  返回要加载item 的索引
     */
    @Override
    public void loadItem(View mView, int pos) {
        
        //为 textview设置 text
        setText(mView,R.id.text1,mDatas.get(pos));
        
        //通过id 获取控件
       // TextView mText = (TextView) getId(mView, R.id.text1);
        
        //通过 findViewById 获取控件
       // View viewById = mView.findViewById(R.id.text1);
        
        
    }
}

初始化控件

public class MainActivity extends AppCompatActivity {

    private ArrayList<String> arrayList=new ArrayList<>(Arrays.asList(
            "测试",
            "测试测试测试",
            "测试测试测试",
            "测试测试测试测试测试",
            "测试测试",
            "测试",
            "测试测试测试测试",
            "测试测试测试",
            "测试"
    ));

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        YbFlowLayout ybFlowLayout = findViewById(R.id.ybFlow);
        //创建适配器
        MyAdapter myAdapter = new MyAdapter(arrayList);
        //绑定适配器
        ybFlowLayout.setAdapter(myAdapter);
        
        //设置最大显示行数
        //ybFlowLayout.setMaxLine(2);
        
        //刷新适配器
        //myAdapter.notifyDataSetChanged();
    }
}

左对齐 tag_gravity="left"

tag_gravity="left"

右对齐 tag_gravity="right"

tag_gravity="right"

居中 tag_gravity="center"

tag_gravity="center"

ybflowlayout's People

Contributors

yangbin8 avatar

Stargazers

 avatar  avatar  avatar

Watchers

James Cloos avatar  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.