1. Home > programming >

Android realizes simple effect of 3D tag cloud

The examples in this article share the specific code for Android to achieve 3D tag cloud effect display for your reference. The specific content is as follows

1. About 3D tag cloud

TagCloudView is a control based entirely on Android ViewGroup. It supports displaying a group of Views as a 3D tag cloud and supports scrolling in all directions.
Link address in GitHub

(1) Effect

The data of the tags on the page can be defined by yourself, and the data page can be selected by sliding.

b1

(2) Used in AndroidStudio

1. Add in build.gradle

compile ‘com.moxun:tagcloudlib:1.0.3'

2. Introduce in the layout file

3. Set Adapter to inherit TagsAdapter and implement the following methods

(1) public int getCount();

Return the number of tags

(2) public View getView(Context context, int position, ViewGroup parent);

Return to each Tag instance

(3) public Object getItem(int position);

Return tag data

(4) public int getPopularity(int position);

Return a value for each Tag, but what does it do?

4. Attribute setting of tag cloud object

Second, simple usage example

(1) Layout file activity_main.xml design

 
 

  

 

(2) Design the layout of the font in the tag cloud

 

 
 

(3) Design font color selector

(Create a color folder under the res folder and create textcolor_tags.xml)

 

 
 
  
  
 

(4) Create adapter class

 package com.lwz.cloud;

 import android.content.Context;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;

 import com.moxun.tagcloudlib.view.TagsAdapter;

 import java.util.List;


 /**
  * Adapter for tag cloud page data
  */

 public class CursorTagsAdapter extends TagsAdapter {


  private List mList;

  public CursorTagsAdapter( List list) {
   this.mList = list;
  }

  @Override
  public int getCount() {
   return mList.size();
  }

  @Override
  public View getView(Context context, int position, ViewGroup parent) {
   TextView tv = (TextView) View.inflate(context, R.layout.item_tag, null);
   tv.setText(getItem(position));
   return tv;
  }

  @Override
  public String getItem(int position) {
   return mList.get(position);
  }

  @Override
  public int getPopularity(int position) {
   return 1;
  }

  @Override
  public void onThemeColorChanged(View view, int themeColor) {

  }
 }

(5) Main method call class

 package com.lwz.cloud;

 import android.os.Bundle;
 import android.support.v7.app.AppCompatActivity;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Toast;

 import com.moxun.tagcloudlib.view.TagCloudView;

 import java.util.ArrayList;
 import java.util.List;

 /**
  * The design of the tag cloud effect interface
  */
 public class MainActivity extends AppCompatActivity implements TagCloudView.OnTagClickListener {
  TagCloudView tcvTags;//Tag cloud object
  List list = new ArrayList<>();//Collection of tag cloud data
  List listClick = new ArrayList<>();//The collection of the data of the clicked tag cloud

  @Override
  protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   //Add data to the collection
   for (int i = 0; i <20; i++) {
    list.add("This is a label" + i);
   }

   tcvTags = (TagCloudView) findViewById(R.id.tcv_tags);
   //Set the click event of the tag cloud
   tcvTags.setOnTagClickListener(this);
   //Set the adapter for the tag cloud
   CursorTagsAdapter adapter = new CursorTagsAdapter(list);
   tcvTags.setAdapter(adapter);
  }

  /**
   * Clicking on the label is a callback method
   */
  @Override
  public void onItemClick(ViewGroup parent, View view, int position) {
   view.setSelected(!view.isSelected());//Set the selected state of the label
   if (view.isSelected()) {
    //Join the collection
    listClick.add(list.get(position));
   } else {
    //Remove collection
    listClick.remove(list.get(position));
   }
   Toast.makeText(this, "Clicked label:" + listClick.toString(), Toast.LENGTH_SHORT).show();
  }
 }

The interface after the program is running:

g1

The interface displayed after clicking a few tabs:

g2

This is a simple example of a tag cloud. This tag cloud will scroll at a constant speed by default.

The above is the whole content of this article, I hope it will be helpful to everyone's study, and I hope you can support it.

Content recommendation: free high-definition PNG material download

This article is published by www.internetweblist.com and does not represent the position of www.internetweblist.com/:http://www.internetweblist.com/programming/31408.html

Contact Us

Online consultation:click here to give a message