SeekBar(拖动条)的简单功能和用法

来源:互联网 发布:埃森哲java面试题 编辑:程序博客网 时间:2024/05/16 00:59

SeekBar(拖动条)的简单功能和用法

这里写图片描述
布局代码

<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="${relativePackage}.${activityClass}" >    <ImageView android:id="@+id/image"        android:layout_width="240dp"        android:layout_height="360dp"        android:src="@drawable/ic_bangumi_guide"/>    <SeekBar         android:id="@+id/seekbar"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:max="250"        android:progress="255"/></LinearLayout>

实现代码

package com.test.seekbar;import android.app.Activity;import android.os.Bundle;import android.widget.ImageView;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;//案例:通过拖动滑块来改变图片的透明度public class MainActivity extends Activity {    private SeekBar seekbar;    private ImageView imageview;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        seekbar = (SeekBar)findViewById(R.id.seekbar);        imageview = (ImageView)findViewById(R.id.image);        seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {            @Override            public void onStopTrackingTouch(SeekBar seekBar) {                // TODO Auto-generated method stub            }            @Override            public void onStartTrackingTouch(SeekBar seekBar) {                // TODO Auto-generated method stub            }            @Override            public void onProgressChanged(SeekBar seekBar, int progress,                    boolean fromUser) {                imageview.setAlpha(progress);            }        });    }}
0 0
原创粉丝点击