标签:
layout文件:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin" 10 tools:context="com.hanqi.testapp2.PractiseActivity" 11 android:orientation="vertical"> 12 13 <SeekBar 14 android:layout_width="match_parent" 15 android:layout_height="wrap_content" 16 android:id="@+id/sb_1" 17 android:max="255" //设置最大进度为255 18 android:progress="0"/> //设置初始进度为0 19 <ImageView 20 android:layout_width="wrap_content" 21 android:layout_height="wrap_content" 22 android:src="@drawable/f4" 23 android:id="@+id/iv_1"/> 24 </LinearLayout>
java类代码:
1 package com.hanqi.testapp2; 2 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.widget.ImageView; 6 import android.widget.SeekBar; 7 8 public class PractiseActivity extends AppCompatActivity { 9 10 SeekBar sb_1; 11 ImageView iv_1; 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.activity_practise); 16 sb_1 =(SeekBar)findViewById(R.id.sb_1); 17 iv_1 =(ImageView)findViewById(R.id.iv_1); 18 iv_1.setImageAlpha(0); //此步骤是设置一开始图片就为透明状态,不设置图片会在开始运行的时候显示 19 sb_1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 20 @Override 21 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 22 23 iv_1.setImageAlpha(progress); 24 } 25 26 @Override 27 public void onStartTrackingTouch(SeekBar seekBar) { 28 29 } 30 31 @Override 32 public void onStopTrackingTouch(SeekBar seekBar) { 33 34 } 35 }); 36 } 37 }
效果为:
标签:
原文地址:http://www.cnblogs.com/hanazawalove/p/5479022.html