android > layout > SeekBar (拉动条)
16lz
2021-12-04
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/v1" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <SeekBar android:id="@+id/seekBar1" android:layout_width="match_parent" android:layout_height="wrap_content" /></LinearLayout>
TestActivity.java
package test.mft;import android.app.Activity;import android.os.Bundle;import android.widget.SeekBar;import android.widget.TextView;import android.widget.Toast;public class TestActivity extends Activity { /** Called when the activity is first created. */private SeekBar s1;private TextView v1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); v1 = (TextView)findViewById(R.id.v1); s1 = (SeekBar)findViewById(R.id.seekBar1); s1.setMax(100); int pro = 50; s1.setProgress(pro); v1.setText(""+pro); s1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { //当停止时public void onStopTrackingTouch(SeekBar arg0) {// TODO Auto-generated method stubv1.setText(""+s1.getProgress());}//当开始拉动时public void onStartTrackingTouch(SeekBar arg0) {// TODO Auto-generated method stubv1.setText(""+s1.getProgress());}//当拉动条 改变值时public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {// TODO Auto-generated method stubv1.setText(""+s1.getProgress());}}); }}
解决不能拖到到 最大值 问题 在 layout 中 设置 android:layout_margin="3dip" 属性即可
修改 风格
<SeekBar android:id="@+id/seekBar1" android:layout_width="130dip" android:layout_height="wrap_content"android:max="100"android:layout_centerVertical="true"android:layout_toLeftOf="@id/sb_value_1"android:paddingLeft="5dip"android:paddingRight="8dip"android:progressDrawable="@drawable/seekbar_bg_img"////------android:thumb="@drawable/seekbar_thumb"////------/>
其中 @drawable/seekbar_bg_img 是背景图片 , @drawable/seekbar_thumb 是拖动按钮
图片参考附件
更多相关文章
- Android(安卓)图片拖动 放大
- Android之SeekBar
- 进度条及拖动条背景颜色设置(progressDrawable)
- 让Android自带的Gallery实现多点缩放,拖动和边界回弹效果,效果流畅
- android中一些view处理(拖动,定位,显示,图层)
- Android(安卓)系统音量最大值的定义位置以及默认值的修改方法
- android xml 常用控件介绍
- Android心率热图实现
- Android:上下拖动切换界面