炫酷自定义翻转View--第三方开源--TagCloudView

 

下载地址:https://github.com/ChinaZeng/3dTagCloudAndroid

 

贴上Demo代码:

 

 <com.moxun.tagcloudlib.view.TagCloudView
        android:id="@+id/tag_cloud"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:autoScrollMode="uniform"
        app:darkColor="#ff00ff00"
        app:lightColor="#ffff0000"
        app:radiusPercent="0.5"
        app:scrollSpeed="3" />

 

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(Context context, final int position, ViewGroup parent) {
        TextView tv = new TextView(context);
        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(100, 100);
        tv.setLayoutParams(lp);
        tv.setText("No." + position);
        tv.setGravity(Gravity.CENTER);

        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);
    }
}

 

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;

import com.moxun.tagcloudlib.view.TagCloudView;

public class MainActivity extends ActionBarActivity {

    @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[13]);
        tagCloudView.setAdapter(tagsAdapter);
    }
}

 

posted on 2016-03-03 11:08  Z2  阅读(1335)  评论(0编辑  收藏  举报

导航