Android實(shí)現(xiàn)3D標(biāo)簽云簡單效果
本文實(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)選擇。
(二)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)行后的界面:
點(diǎn)擊幾個(gè)標(biāo)簽后顯示的界面:
這就是標(biāo)簽云的簡單示例。這個(gè)標(biāo)簽云默認(rèn)情況下是會(huì)勻速滾動(dòng)的。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue實(shí)現(xiàn)標(biāo)簽云效果的方法詳解
- 基于python3生成標(biāo)簽云代碼解析
- 深入解析JS實(shí)現(xiàn)3D標(biāo)簽云的原理與方法
- 如何通過Python實(shí)現(xiàn)標(biāo)簽云算法
- wordpress自定義標(biāo)簽云與隨機(jī)獲取標(biāo)簽的方法詳解
- Android實(shí)現(xiàn)隨機(jī)圓形云標(biāo)簽效果
- Android自定義控件ViewGroup實(shí)現(xiàn)標(biāo)簽云
- Android TagCloudView云標(biāo)簽的使用方法
- Android實(shí)現(xiàn)3D云標(biāo)簽效果
- Android實(shí)現(xiàn)3D標(biāo)簽云效果
- android隨機(jī)生成圓形云標(biāo)簽效果
- jQuery簡單實(shí)現(xiàn)彩色云標(biāo)簽效果示例
- javascript實(shí)現(xiàn)動(dòng)態(tài)標(biāo)簽云
- vue實(shí)現(xiàn)標(biāo)簽云效果的示例
相關(guān)文章
android scrollview 自動(dòng)滾動(dòng)到頂部或者底部的實(shí)例
這篇文章主要介紹了android scrollview 自動(dòng)滾動(dòng)到頂部或者底部的相關(guān)資料,需要的朋友可以參考下2017-06-06Android模擬實(shí)現(xiàn)網(wǎng)易新聞客戶端
這篇文章主要為大家詳細(xì)介紹了Android模擬實(shí)現(xiàn)網(wǎng)易新聞客戶端,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05超精準(zhǔn)的Android手機(jī)計(jì)步器開發(fā)
這篇文章主要為大家詳細(xì)介紹了超精準(zhǔn)的Android手機(jī)計(jì)步器開發(fā)過程,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10Android調(diào)用系統(tǒng)裁剪的實(shí)現(xiàn)方法
下面小編就為大家分享一篇Android調(diào)用系統(tǒng)裁剪的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-02-02Android 點(diǎn)擊editview以外位置實(shí)現(xiàn)隱藏輸入法
這篇文章主要介紹了Android 點(diǎn)擊editview以外位置實(shí)現(xiàn)隱藏輸入法的相關(guān)資料,需要的朋友可以參考下2017-06-06