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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
LevelDemo.rar (40个子文件)
LevelDemo
gradlew 5KB
LevelDemo.iml 886B
settings.gradle 16B
gradle
wrapper
gradle-wrapper.properties 236B
gradle-wrapper.jar 52KB
local.properties 494B
gradlew.bat 2KB
gradle.properties 747B
.gitignore 127B
app
src
androidTest
java
com
leveldemo
ExampleInstrumentedTest.java 756B
test
java
com
leveldemo
ExampleUnitTest.java 407B
main
AndroidManifest.xml 727B
res
mipmap-hdpi
ic_launcher.png 3KB
ic_launcher_round.png 4KB
mipmap-xxxhdpi
ic_launcher.png 10KB
ic_launcher_round.png 14KB
mipmap-xhdpi
ic_launcher.png 5KB
ic_launcher_round.png 6KB
mipmap-mdpi
ic_launcher.png 2KB
ic_launcher_round.png 2KB
drawable
shape_level_yellow.xml 196B
layout
item_lv_lastpoint.xml 893B
item_lv_tagpoint.xml 891B
activity_main.xml 2KB
drawable-xhdpi
level_white_point.png 1KB
exp_perent_bg.9.png 388B
level_red_point.png 1KB
values
colors.xml 296B
strings.xml 75B
styles.xml 394B
mipmap-xxhdpi
ic_launcher.png 8KB
ic_launcher_round.png 10KB
java
com
leveldemo
DensityUtils.java 1KB
MainActivity.java 6KB
SimpleLevelModel.java 454B
libs
app.iml 10KB
.gitignore 8B
build.gradle 958B
proguard-rules.pro 940B
build.gradle 521B
共 40 条
- 1
资源评论
FC小司
- 粉丝: 27
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功