GithubHelp home page GithubHelp logo

tagcloud's Introduction

tagcloud

根据服务器返回数据的数量,每个字段的大小进行自适应布局

用法

<fyales.com.tagcloud.library.TagCloudLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tagSpacing="15dp"
    app:lineSpacing="10dp"/>
  • tagSpacing属性:各个标签之间的距离
  • lineSpacing属性:行间距

Java代码

    mContainer = (TagCloudLayout) findViewById(R.id.container);
    mList = new ArrayList<>();
    mList.add("中华人名共和国");
    mList.add("大韩民国");
    mList.add("日本");
    mList.add("朝鲜");
    mList.add("**");
    mList.add("香港特别行政区");
    mList.add("澳门特别行政区");
    mList.add("越南");
    mList.add("老挝");
    mList.add("柬埔寨");
    mList.add("泰国");
    mList.add("缅甸");
    mList.add("马来西亚");
    mList.add("新加坡");
    mList.add("印度尼西亚");
    mList.add("文莱");
    mList.add("菲律宾");
    mAdapter = new TagBaseAdapter(this,mList);
    findViewById(R.id.add_btn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mList.add("东帝汶");
            mAdapter.notifyDataSetChanged();
        }
    });
    mContainer.setAdapter(mAdapter);
    mContainer.setItemClickListener(new TagCloudLayout.TagItemClickListener() {
        @Override
        public void itemClick(int position) {
            Toast.makeText(MainActivity.this,mList.get(position),Toast.LENGTH_SHORT).show();
        }
    });

实现效果

图片

gradle引用(仓库为JCenter)

dependencies {
	compile 'com.fyales.android:library:1.0.2'
}

1.0.2更新

  • 允许用户自定义,自己写一个adapter即可
  • 重构代码

tagcloud's People

Watchers

trz 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.