zoukankan      html  css  js  c++  java
  • seekbar拖动条控件

    seekbar拖动条控件可以通过拖动条改变当前的值,可以用seebar设置具有一定范围的变量值。如:

    在.xml文件中:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView android:id="@+id/textview1" android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <TextView android:id="@+id/textview2" android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <SeekBar android:id="@+id/seekbar1" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:max="100"
            android:progress="30"></SeekBar>
    
        <SeekBar android:id="@+id/seekbar2" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:max="100"
            android:progress="30" android:secondaryProgress="60"></SeekBar>
    </LinearLayout>

    在.java文件中:

    public class Main extends Activity implements OnSeekBarChangeListener {
        /** Called when the activity is first created. */
        private TextView textView1, textView2;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            textView1 = (TextView) this.findViewById(R.id.textview1);
            textView2 = (TextView) this.findViewById(R.id.textview2);
            SeekBar seekBar1 = (SeekBar) this.findViewById(R.id.seekbar1);
            SeekBar seekBar2 = (SeekBar) this.findViewById(R.id.seekbar2);
            seekBar1.setOnSeekBarChangeListener(this);
            seekBar2.setOnSeekBarChangeListener(this);
        }
    
        // 当滑动滑竿的时候会触发的事件
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub
            if (seekBar.getId() == R.id.seekbar1) {
                textView1.setText("seekbar1的当前位置是:" + progress);
            } else {
                textView2.setText("seekbar2的当前位置是:" + progress);
            }
        }
    
        // 表示从哪里开始拖动
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
            if (seekBar.getId() == R.id.seekbar1) {
                textView1.setText("seekbar1开始拖动");
            } else {
                textView1.setText("seekbar2开始拖动");
            }
        }
    
        // 表示从哪里结束拖动
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
            if (seekBar.getId() == R.id.seekbar1) {
                textView1.setText("seekbar1停止拖动");
            } else {
                textView1.setText("seekbar2停止拖动");
            }
        }
    }

    运行结果:

  • 相关阅读:
    PAT:1069. The Black Hole of Numbers (20) AC
    PAT:1008. Elevator (20) AC
    PAT:1052. Linked List Sorting (25) 部分错误
    PAT:1032. Sharing (25) AC
    PAT:1059. Prime Factors (25) AC
    素数表(筛选法)
    PAT:1048. Find Coins (25)(双指针法) AC
    PAT:1048. Find Coins (25)(二分查找) AC
    iOS 9.0 设置状态栏颜色 和隐藏
    UIPageViewController用法
  • 原文地址:https://www.cnblogs.com/SoulCode/p/5370091.html
Copyright © 2011-2022 走看看