亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android實(shí)現(xiàn)3D標(biāo)簽云簡單效果

 更新時(shí)間:2021年06月23日 15:26:28   作者:崢嶸life  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)3D標(biāo)簽云簡單效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android實(shí)現(xiàn)3D標(biāo)簽云效果展示的具體代碼,供大家參考,具體內(nèi)容如下

一、關(guān)于3D標(biāo)簽云

TagCloudView是一個(gè)完全基于Android ViewGroup編寫的控件,支持將一組View展示為一個(gè)3D標(biāo)簽云,并支持全方向滾動(dòng)。
GitHub中的鏈接地址

(一)效果

頁面上標(biāo)簽的數(shù)據(jù)可以自己定義,數(shù)據(jù)頁面可以滑動(dòng)選擇。

b1

(二)AndroidStudio中使用

1.在build.gradle中添加

compile ‘com.moxun:tagcloudlib:1.0.3'

2.在布局文件中引入

3.設(shè)置Adapter 繼承TagsAdapter,實(shí)現(xiàn)以下方法

(1)public int getCount();

返回Tag數(shù)量

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

返回每個(gè)Tag實(shí)例

(3)public Object getItem(int position);

返回Tag數(shù)據(jù)

(4)public int getPopularity(int position);

針對(duì)每個(gè)Tag返回一個(gè)值,但是什么作用

4.標(biāo)簽云對(duì)象的屬性設(shè)置

二、簡單的使用示例

(一)布局文件activity_main.xml設(shè)計(jì)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

 <com.moxun.tagcloudlib.view.TagCloudView
  android:id="@+id/tcv_tags"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:autoScrollMode="uniform"
  app:radiusPercent="0.8" />

</RelativeLayout>

(二)設(shè)計(jì)標(biāo)簽云中的字體的布局

<?xml version="1.0" encoding="utf-8"?>

<!--單個(gè)標(biāo)簽云中的文本的視圖-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="標(biāo)簽云"
 android:textColor="@color/textcolor_tags"
  />

(三)設(shè)計(jì)字體的顏色選擇器

(res文件夾下創(chuàng)建color文件夾,創(chuàng)建textcolor_tags.xml)

<?xml version="1.0" encoding="utf-8"?>

<!--標(biāo)簽云的文本的字體的顏色選擇器-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:color="#f0f" android:state_selected="true" />
 <item android:color="#000" android:state_selected="false" />
</selector>

(四)創(chuàng)建適配器的類

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;


/**
 * 標(biāo)簽云頁面數(shù)據(jù)的適配器
 */

public class CursorTagsAdapter extends TagsAdapter {


 private List<String> mList;

 public CursorTagsAdapter( List<String> 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) {

 }
}

(五)主方法調(diào)用類

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;

/**
 * 標(biāo)簽云效果界面的設(shè)計(jì)
 */
public class MainActivity extends AppCompatActivity implements TagCloudView.OnTagClickListener {
 TagCloudView tcvTags;//標(biāo)簽云對(duì)象
 List<String> list = new ArrayList<>();//標(biāo)簽云數(shù)據(jù)的集合
 List<String> listClick = new ArrayList<>();//點(diǎn)擊過的標(biāo)簽云的數(shù)據(jù)的集合

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  //給集合添加數(shù)據(jù)
  for (int i = 0; i < 20; i++) {
   list.add("這是標(biāo)簽" + i);
  }

  tcvTags = (TagCloudView) findViewById(R.id.tcv_tags);
  //設(shè)置標(biāo)簽云的點(diǎn)擊事件
  tcvTags.setOnTagClickListener(this);
  //給標(biāo)簽云設(shè)置適配器
  CursorTagsAdapter adapter = new CursorTagsAdapter(list);
  tcvTags.setAdapter(adapter);
 }

 /**
  * 點(diǎn)擊標(biāo)簽是回調(diào)的方法
  */
 @Override
 public void onItemClick(ViewGroup parent, View view, int position) {
  view.setSelected(!view.isSelected());//設(shè)置標(biāo)簽的選擇狀態(tài)
  if (view.isSelected()) {
   //加入集合
   listClick.add(list.get(position));
  } else {
   //移除集合
   listClick.remove(list.get(position));
  }
  Toast.makeText(this, "點(diǎn)擊過的標(biāo)簽:" + listClick.toString(), Toast.LENGTH_SHORT).show();
 }
}

程序運(yùn)行后的界面:

g1

點(diǎn)擊幾個(gè)標(biāo)簽后顯示的界面:

g2

這就是標(biāo)簽云的簡單示例。這個(gè)標(biāo)簽云默認(rèn)情況下是會(huì)勻速滾動(dòng)的。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論