本文實例為大家分享了Android實現(xiàn)3D標簽云效果展示的具體代碼,供大家參考,具體內(nèi)容如下
成都創(chuàng)新互聯(lián)專業(yè)IDC數(shù)據(jù)服務(wù)器托管提供商,專業(yè)提供成都服務(wù)器托管,服務(wù)器租用,成都棕樹機房,成都棕樹機房,成都多線服務(wù)器托管等服務(wù)器托管服務(wù)。
一、關(guān)于3D標簽云
TagCloudView是一個完全基于Android ViewGroup編寫的控件,支持將一組View展示為一個3D標簽云,并支持全方向滾動。
GitHub中的鏈接地址
(一)效果
頁面上標簽的數(shù)據(jù)可以自己定義,數(shù)據(jù)頁面可以滑動選擇。
(二)AndroidStudio中使用
1.在build.gradle中添加
compile ‘com.moxun:tagcloudlib:1.0.3'
2.在布局文件中引入
3.設(shè)置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.標簽云對象的屬性設(shè)置
二、簡單的使用示例
(一)布局文件activity_main.xml設(shè)計
<?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è)計標簽云中的字體的布局
<?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" />
(三)設(shè)計字體的顏色選擇器
(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) { } }
(五)主方法調(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; /** * 標簽云效果界面的設(shè)計 */ 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); //設(shè)置標簽云的點擊事件 tcvTags.setOnTagClickListener(this); //給標簽云設(shè)置適配器 CursorTagsAdapter adapter = new CursorTagsAdapter(list); tcvTags.setAdapter(adapter); } /** * 點擊標簽是回調(diào)的方法 */ @Override public void onItemClick(ViewGroup parent, View view, int position) { view.setSelected(!view.isSelected());//設(shè)置標簽的選擇狀態(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(); } }
程序運行后的界面:
點擊幾個標簽后顯示的界面:
這就是標簽云的簡單示例。這個標簽云默認情況下是會勻速滾動的。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
新聞標題:Android實現(xiàn)3D標簽云簡單效果
網(wǎng)頁路徑:http://muchs.cn/article28/jcpgcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化、、網(wǎng)站維護、企業(yè)建站、網(wǎng)站設(shè)計、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)