<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical"
android:padding="15dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="技能名称"
android:textColor="@color/black"
android:textSize="14sp"
/>
<TextView
android:id="@+id/del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="删除"
android:textColor="@color/lagou_user_setting_btn"
android:textSize="14sp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
>
<TextView
android:id="@+id/degree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="技能掌握程度"
android:textColor="@color/black"
android:textSize="14sp"
/>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:layout_below="@+id/degree"
android:progressDrawable="@drawable/style_seekbar" //样式
android:thumb="@drawable/ic_message_invite"/> //拖动按钮图片
</RelativeLayout>
</LinearLayout>
样式
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="10dip"/>
<gradient
android:angle="270"
android:centerColor="#ffffff" //未滑动颜色
android:centerY="0.45"
android:endColor="#d4d4d4"
android:startColor="#d4d4d4"/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="10dip"/>
<gradient
android:angle="270"
android:centerColor="#ffff7452" //滑动过后颜色
android:centerY="0.45"
android:endColor="#ffff7452"
android:startColor="#ffff7452"/>
</shape>
</clip>
</item>
</layer-list>
监听
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//name.setText(progress+"");
if (progress < 20) {
degree.setText("了解");
} else if (20 <= progress && progress < 40) {
degree.setText("熟悉");
} else if (40 <= progress && progress < 60) {
degree.setText("掌握");
} else if (60 <= progress && progress < 80) {
degree.setText("精通");
} else if (80 <= progress && progress < 100) {
degree.setText("专家");
}
//文字随滑动块一起滑动,有偏移
int position = seekBar.getProgress();
float x = seekbar.getWidth();
float seekbarWidth = seekbar.getX();
float y = seekbar.getY();
float width = (position * x) / 100 + seekbarWidth;
degree.setX(width);
degree.setY(y - 40);
degree.invalidate();
/* RelativeLayout.LayoutParams paramsStrength = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
paramsStrength.leftMargin = (int) (progress * fDensity);
degree.setLayoutParams(paramsStrength);*/
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});