package com.leveldemo;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
//横向seekbar的容器
private HorizontalScrollView horizontalScrollView;
private LinearLayout contentLl;
//经验值悬浮窗
private TextView expTv;
//当前等级的百分比
private double percent;
//横向seekbar的宽度
private int width;
//底色白线
private View whiteLine;
//经验红线
private View redLine;
private SparseArray<ImageView> imageViews;
private SparseArray<TextView> textviews;
private List<SimpleLevelModel> simpleLevelModelList;
private int myLevel=15;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
}
private void initView() {
horizontalScrollView= (HorizontalScrollView) findViewById(R.id.scrollview_level);
contentLl= (LinearLayout) findViewById(R.id.ll_content_img);
expTv = (TextView) findViewById(R.id.tv_exp);
redLine=findViewById(R.id.red_line);
whiteLine=findViewById(R.id.white_line);
expTv.setText("10234");
simpleLevelModelList=new ArrayList<>();
for (int i = 0; i < 50; i++) {
SimpleLevelModel moel=new SimpleLevelModel();
moel.setLevelId(i+1);
simpleLevelModelList.add(moel);
}
}
private void initData() {
if (imageViews == null){
imageViews = new SparseArray<>();
}
if(textviews==null){
textviews=new SparseArray<>();
}
for (int i = 0; i <simpleLevelModelList.size(); i++) {
if(i!=simpleLevelModelList.size()-1){
contentLl.addView(getRadioView(i,false),i);
}else {
contentLl.addView(getRadioView(i,true),i);
}
}
contentLl.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
width=contentLl.getWidth();
contentLl.getViewTreeObserver().removeOnGlobalLayoutListener(this);
setDefault(myLevel);
}
});
}
private View getRadioView(final int i,boolean isLast){
View view = null;
if(!isLast){
view = LayoutInflater.from(this).inflate(R.layout.item_lv_tagpoint,contentLl,false);
ImageView imageview = (ImageView) view.findViewById(R.id.image);
TextView textview = (TextView) view.findViewById(R.id.tv_level_seekbar);
textview.setText("LV"+simpleLevelModelList.get(i).getLevelId());
imageViews.put(i,imageview);
textviews.put(i,textview);
}else {
view = LayoutInflater.from(this).inflate(R.layout.item_lv_lastpoint,contentLl,false);
ImageView imageview = (ImageView) view.findViewById(R.id.image);
TextView textview = (TextView) view.findViewById(R.id.tv_level_seekbar);
textview.setText("LV"+simpleLevelModelList.get(i).getLevelId());
imageViews.put(i,imageview);
textviews.put(i,textview);
}
return view;
}
private void setDefault(int level) {
percent= 0.82;
for (int i = 0; i <imageViews.size() ; i++) {
if(i<level){
imageViews.get(i).setImageResource(R.drawable.level_red_point);
}else {
imageViews.get(i).setImageResource(R.drawable.level_white_point);
}
}
// textviews.get(level).setText("LV"+simpleLevelModelList.get(level).getLevelId());
// backLine.getLayoutParams().width= width-((int)DensityUtils.dp2px(getApplicationContext(),itemwidth));
//进度底色
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) whiteLine.getLayoutParams();
lp.width= (simpleLevelModelList.size()-1)* DensityUtils.dp2px(getApplicationContext(),100F);
lp.setMargins(DensityUtils.dp2px(getApplicationContext(),50F),0,0,0);
// backLine.getLayoutParams().width= (titles.size()-1)*DensityUtils.dp2px(getApplicationContext(),100F);
whiteLine.setLayoutParams(lp);
RelativeLayout.LayoutParams lp1 = (RelativeLayout.LayoutParams) redLine.getLayoutParams();
lp1.width= (myLevel-1)*DensityUtils.dp2px(getApplicationContext(),100F)+(int)(percent*DensityUtils.dp2px(getApplicationContext(),100F));
lp1.setMargins(DensityUtils.dp2px(getApplicationContext(),50F),0,0,0);
redLine.setLayoutParams(lp1);
horizontalScrollView.scrollTo(lp1.width,0);
RelativeLayout.LayoutParams lp2 = (RelativeLayout.LayoutParams) expTv.getLayoutParams();
//偏移时需要加悬浮窗宽度+point的宽度
lp2.setMargins(lp1.width+DensityUtils.dp2px(getApplicationContext(),50F)-expTv.getWidth()/2,0,0,DensityUtils.dp2px(getApplicationContext(),10F));
expTv.setLayoutParams(lp2);
}
}
FC小司
- 粉丝: 27
- 资源: 13
最新资源
- 电机NVH仿真 1)Maxwell导入电机模型建模,径向电磁力讨论分析 2)加速工况等效声功率辐射噪声计算 3)电机壳体模态分析 模型+操作详解
- 电力电子中BUCK降压变换器的工作原理及其设计分析
- 基于java+springboot+vue+mysql的水果在线销售系统 源码+数据库+论文(高分毕业设计).zip
- 嵌入式系统开发:深入了解ChibiOS实时操作系统的架构与应用(中文)
- 电力电子升压变换器(BOOST电路)的工作原理与参数设计分析
- 基于java+springboot+vue+mysql的明星周边商城系统 源码+数据库+论文(高分毕业设计).zip
- 基于java+springboot+vue+mysql的农产品电商平台 源码+数据库+论文(高分毕业设计).zip
- 基于java+springboot+vue+mysql的体育商品推荐系统 源码+数据库+论文(高分毕业设计).zip
- 基于java+springboot+vue+mysql的校园数字化图书馆系统 源码+数据库+论文(高分毕业设计).zip
- 基于java+springboot+vue+mysql的网络海鲜市场系统 源码+数据库+论文(高分毕业设计).zip
- zzb_edge_chrome_30.2.2.zip
- 基于java+springboot+vue+mysql的新能源汽车个性化推荐系统 源码+数据库+论文(高分毕业设计).zip
- 基于java+springboot+vue+mysql的在线考试系统 源码+数据库+论文(高分毕业设计).zip
- 快速会议排座生成器,导入有姓名和备注(空的表示来,非空表示)列的EXCEL文件,设置左、中、右区域的座位数,生成每个人的位置图
- 基于java+springboot+vue+mysql的游戏账号交易系统 源码+数据库+论文(高分毕业设计).zip
- windowsdesktop-runtime-7.0.20-win-x86.exe
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈