Android 仿soul首页星球旋转,可上下左右方向旋转

Android 仿soul首页星球旋转,可上下左右方向旋转,第1张

Android 仿soul首页星球旋转,可上下左右方向旋转

    // 3d星球视图旋转样式
    implementation 'com.moxun:tagcloudlib:1.2.0'

adapter继承TagsAdapter

package com.demo.cn;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.moxun.tagcloudlib.view.TagsAdapter;

import java.util.List;


public class StarViewAdapter extends TagsAdapter {

    private Context mContext;
    private List mList;
    private LayoutInflater inflater;

    public StarViewAdapter(Context mContext, List mList) {
        this.mContext = mContext;
        this.mList = mList;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    
    @Override
    public int getCount() {
        return mList.size();
    }

    
    @Override
    public View getView(Context context, int position, ViewGroup parent) {
        StarModel model = mList.get(position);
        View mView = null;
        ViewHolder viewHolder = null;
        if (mView == null) {
            viewHolder = new ViewHolder();
            //初始化View
            mView = inflater.inflate(R.layout.layout_3d_item, null);
            //初始化控件
            viewHolder.tv_star_name = mView.findViewById(R.id.txt_name);
            mView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) mView.getTag();
        }
        viewHolder.tv_star_name.setText(model.getName());
        return mView;
    }

    
    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    
    @Override
    public int getPopularity(int position) {
        return 7;
    }

    
    @Override
    public void onThemeColorChanged(View view, int themeColor) {

    }

    class ViewHolder {
        private TextView tv_star_name;
    }

}

layout_3d_item




    

Mainactivity

package com.demo.cn;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.moxun.tagcloudlib.view.TagCloudView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {


    @BindView(R.id.mTagCloudView)
    TagCloudView mTagCloudView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initdata();
    }

    private void initdata() {
        List starModel = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            starModel.add(new StarModel("群聊名称" + i));
        }
        StarViewAdapter mTagCloudViewAdapter = new StarViewAdapter(this, starModel);
        mTagCloudView.setAdapter(mTagCloudViewAdapter);

        // 设置 3d Tag View 条目点击事件
        mTagCloudView.setonTagClickListener(new TagCloudView.onTagClickListener() {
            @Override
            public void onItemClick(ViewGroup parent, View view, int position) {
                Toast.makeText(MainActivity.this, "您点击了:" + starModel.get(position).getName(), Toast.LENGTH_LONG).show();
            }
        });

    }

}

activity_main




    


StarModel

public class StarModel {
    private String name;

    public StarModel(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5707844.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存