Android實現(xiàn)3D標簽云效果
更新時間:2021年06月23日 15:27:14 作者:MrZhao_PerfectCode
這篇文章主要為大家詳細介紹了Android實現(xiàn)3D標簽云效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
最近業(yè)務(wù)需求,要求實現(xiàn)一個3D星球環(huán)繞效果,經(jīng)過百般查找,終于找到了這個功能。
來先看看效果圖:
首先還是添加第三方依賴庫:
compile 'com.moxun:tagcloudlib:1.1.0'
布局:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.administrator.my3d_demo.MainActivity"> <com.moxun.tagcloudlib.view.TagCloudView android:id="@+id/tag_cloud" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" app:autoScrollMode="uniform" app:darkColor="#ff00ff00" app:lightColor="#ffff0000" app:radiusPercent="0.5" app:scrollSpeed="3" /> </android.support.constraint.ConstraintLayout>
MainActivity代碼:
package com.example.administrator.my3d_demo; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.moxun.tagcloudlib.view.TagCloudView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TagCloudView tagCloudView = (TagCloudView) findViewById(R.id.tag_cloud); tagCloudView.setBackgroundColor(Color.LTGRAY); TextTagsAdapter tagsAdapter = new TextTagsAdapter(new String[20]); tagCloudView.setAdapter(tagsAdapter); } }
一個適配器代碼:
package com.example.administrator.my3d_demo; import android.content.Context; import android.support.annotation.NonNull; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.moxun.tagcloudlib.view.TagsAdapter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; public class TextTagsAdapter extends TagsAdapter { private List<String> dataSet = new ArrayList<>(); public TextTagsAdapter(@NonNull String... data) { dataSet.clear(); Collections.addAll(dataSet, data); } @Override public int getCount() { return dataSet.size(); } @Override public View getView(final Context context, final int position, ViewGroup parent) { String[] name = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}; /*int[] name={R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher, R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher, R.mipmap.ic_launcher,R.mipmap.ic_launcher,R.mipmap.ic_launcher};*/ Random rand = new Random(); int randNum = rand.nextInt(9); TextView tv = new TextView(context); ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(100, 100); tv.setLayoutParams(lp); tv.setText("No." + name[randNum]); tv.setGravity(Gravity.CENTER); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.e("Click", "Tag " + position + " clicked."); } }); return tv; } @Override public Object getItem(int position) { return dataSet.get(position); } @Override public int getPopularity(int position) { return position % 7; } @Override public void onThemeColorChanged(View view, int themeColor) { ((TextView) view).setTextColor(themeColor); } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 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)標簽云效果的示例
相關(guān)文章
Android開發(fā)之瀏覽器用法實例詳解(調(diào)用uc,opera,qq瀏覽器訪問網(wǎng)頁)
這篇文章主要介紹了Android開發(fā)之瀏覽器用法,結(jié)合實例形式詳細分析了Android調(diào)用瀏覽器的具體步驟與相關(guān)使用技巧,需要的朋友可以參考下2016-01-01Android實現(xiàn)點擊WebView界面中圖片滑動瀏覽與保存圖片功能
大家在日常使用spp流量文章的時候經(jīng)常會遇到這樣的一個功能,點擊文章的圖片進入圖片的瀏覽模式,可以左右滑動圖片瀏覽,并且可以實現(xiàn)保存圖片的功能,所以本文主要就介紹了在Android如何實現(xiàn)點擊WebView界面中圖片滑動瀏覽與保存圖片功能,需要的朋友可以參考下。2017-04-04Android GPS室內(nèi)定位問題的解決方法(location為null)
這篇文章主要為大家詳細介紹了Android GPS室內(nèi)定位問題的解決方法,location為null,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02Android實現(xiàn)EventBus登錄界面與傳值(粘性事件)
這篇文章主要為大家詳細介紹了Android實現(xiàn)EventBus登錄界面與傳值,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11