首页 > 代码库 > 安卓学习-界面-ui-SeekBar

安卓学习-界面-ui-SeekBar

和processbar差不多,只不过他的进度是可以拖动的,直接看效果

 

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/linearLayout1"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical"    android:padding="10dp" >    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="改变图片透明度"        android:textAppearance="?android:attr/textAppearanceLarge" />    <SeekBar        android:id="@+id/seekBar1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:max="255"        android:progress="255"        android:thumb="@drawable/ic_launcher"         />    <ImageView        android:id="@+id/imageView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/pic1" /></LinearLayout>
View Code

MainActivity.java

public class MainActivity extends Activity{    SeekBar seekBar1;    ImageView imageView1;        Handler handler=new Handler(){        public void handleMessage(Message msg) {            if(msg.what==123){                int alpha =msg.getData().getInt("alpha");                imageView1.setImageAlpha(alpha);            }        }    };    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                imageView1=(ImageView)findViewById(R.id.imageView1);        seekBar1=(SeekBar)findViewById(R.id.seekBar1);        seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {                        @Override            public void onStopTrackingTouch(SeekBar seekBar) {                // TODO 自动生成的方法存根                            }                        @Override            public void onStartTrackingTouch(SeekBar seekBar) {                // TODO 自动生成的方法存根                            }                        @Override            public void onProgressChanged(SeekBar seekBar, int progress,                    boolean fromUser) {                Message msg=new Message();                msg.what=123;                Bundle data=new Bundle();                data.putInt("alpha", progress);                msg.setData(data);                handler.sendMessage(msg);                            }        });    }}
View Code

 

安卓学习-界面-ui-SeekBar