zoukankan      html  css  js  c++  java
  • Android基础控件之SeekBar(拖动条)

    基础控件SeekBar用于触摸拖动,eg:手机中的音量的调节、亮度调节等,可用到SeekBar实现。

    此处以调节音量大小为例:

    <-------------------XML文件------------------>

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.example20.MainActivity">
    
       <TextView
    android:id="@+id/text_view"
    android:textSize="20dp"
    android:text="音量大小: 0"
    android:paddingTop="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:textAlignment="center"
    android:textColor="#2d4a87"
    android:background="#72b3cf"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
        </TextView>
    <!-----android:max用于设置拖动条的最大值
    android:progress用于设置拖动条的当前进度
    android:thumb该属性指定一个图片作为滑动条的滑块----->
        <SeekBar//定义SeekBar控件
    android:id="@+id/seek_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
    </LinearLayout>
    

    <-----------------------------MainActivity文件---------------------------->

    package com.example.example20;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.SeekBar;
    import android.widget.TextView;
    
    public class MainActivity extends AppCompatActivity {
        final static double MAX=100;
        SeekBar seekBar;
        TextView textView;
        @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            seekBar=(SeekBar)findViewById(R.id.seek_bar);
            textView=(TextView)findViewById(R.id.text_view);
            seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {//设置监听
                @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    textView.setText("音量大小: "+(int)seekBar.getProgress());   //根据拖动位置设置textView的值
    }
    
                @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    
                }
    
                @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    
                }
            });
        }
    }
    
  • 相关阅读:
    Service Mesh 在百度网盘数万后端的落地实践
    垃圾回收GC3种算法的衍生品 增量回收:预测和控制GC所产生的中断时间
    cv_list
    段式内存管理
    页式内存管理
    基本内存管理
    内存抖动
    内存管理 垃圾回收 C语言内存分配 垃圾回收3大算法 引用计数3个缺点
    DEDECMS后台传附件图片出现Upload filetype not allow解决办法
    浅谈dedecms模板引擎工作原理及自定义标签
  • 原文地址:https://www.cnblogs.com/xpfei/p/7450820.html
Copyright © 2011-2022 走看看