Android實現(xiàn)3D標簽云簡單效果
本文實例為大家分享了Android實現(xiàn)3D標簽云效果展示的具體代碼,供大家參考,具體內容如下
一、關于3D標簽云
TagCloudView是一個完全基于Android ViewGroup編寫的控件,支持將一組View展示為一個3D標簽云,并支持全方向滾動。
GitHub中的鏈接地址
(一)效果
頁面上標簽的數(shù)據(jù)可以自己定義,數(shù)據(jù)頁面可以滑動選擇。
(二)AndroidStudio中使用
1.在build.gradle中添加
compile ‘com.moxun:tagcloudlib:1.0.3'
2.在布局文件中引入
3.設置Adapter 繼承TagsAdapter,實現(xiàn)以下方法
(1)public int getCount();
返回Tag數(shù)量
(2)public View getView(Context context, int position, ViewGroup parent);
返回每個Tag實例
(3)public Object getItem(int position);
返回Tag數(shù)據(jù)
(4)public int getPopularity(int position);
針對每個Tag返回一個值,但是什么作用
4.標簽云對象的屬性設置
二、簡單的使用示例
(一)布局文件activity_main.xml設計
<?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>
(二)設計標簽云中的字體的布局
<?xml version="1.0" encoding="utf-8"?> <!--單個標簽云中的文本的視圖--> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="標簽云" android:textColor="@color/textcolor_tags" />
(三)設計字體的顏色選擇器
(res文件夾下創(chuàng)建color文件夾,創(chuàng)建textcolor_tags.xml)
<?xml version="1.0" encoding="utf-8"?> <!--標簽云的文本的字體的顏色選擇器--> <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; /** * 標簽云頁面數(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) { } }
(五)主方法調用類
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; /** * 標簽云效果界面的設計 */ public class MainActivity extends AppCompatActivity implements TagCloudView.OnTagClickListener { TagCloudView tcvTags;//標簽云對象 List<String> list = new ArrayList<>();//標簽云數(shù)據(jù)的集合 List<String> listClick = new ArrayList<>();//點擊過的標簽云的數(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("這是標簽" + i); } tcvTags = (TagCloudView) findViewById(R.id.tcv_tags); //設置標簽云的點擊事件 tcvTags.setOnTagClickListener(this); //給標簽云設置適配器 CursorTagsAdapter adapter = new CursorTagsAdapter(list); tcvTags.setAdapter(adapter); } /** * 點擊標簽是回調的方法 */ @Override public void onItemClick(ViewGroup parent, View view, int position) { view.setSelected(!view.isSelected());//設置標簽的選擇狀態(tài) if (view.isSelected()) { //加入集合 listClick.add(list.get(position)); } else { //移除集合 listClick.remove(list.get(position)); } Toast.makeText(this, "點擊過的標簽:" + listClick.toString(), Toast.LENGTH_SHORT).show(); } }
程序運行后的界面:
點擊幾個標簽后顯示的界面:
這就是標簽云的簡單示例。這個標簽云默認情況下是會勻速滾動的。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- vue實現(xiàn)標簽云效果的方法詳解
- 基于python3生成標簽云代碼解析
- 深入解析JS實現(xiàn)3D標簽云的原理與方法
- 如何通過Python實現(xiàn)標簽云算法
- wordpress自定義標簽云與隨機獲取標簽的方法詳解
- Android實現(xiàn)隨機圓形云標簽效果
- Android自定義控件ViewGroup實現(xiàn)標簽云
- Android TagCloudView云標簽的使用方法
- Android實現(xiàn)3D云標簽效果
- Android實現(xiàn)3D標簽云效果
- android隨機生成圓形云標簽效果
- jQuery簡單實現(xiàn)彩色云標簽效果示例
- javascript實現(xiàn)動態(tài)標簽云
- vue實現(xiàn)標簽云效果的示例
相關文章
android scrollview 自動滾動到頂部或者底部的實例
這篇文章主要介紹了android scrollview 自動滾動到頂部或者底部的相關資料,需要的朋友可以參考下2017-06-06Android模擬實現(xiàn)網(wǎng)易新聞客戶端
這篇文章主要為大家詳細介紹了Android模擬實現(xiàn)網(wǎng)易新聞客戶端,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05Android調用系統(tǒng)裁剪的實現(xiàn)方法
下面小編就為大家分享一篇Android調用系統(tǒng)裁剪的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02Android 點擊editview以外位置實現(xiàn)隱藏輸入法
這篇文章主要介紹了Android 點擊editview以外位置實現(xiàn)隱藏輸入法的相關資料,需要的朋友可以參考下2017-06-06