Android實現拖動進度條改變圖片透明度

來源:互聯網
上載者:User

標籤:

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     <SeekBar14         android:layout_width="match_parent"15         android:layout_height="wrap_content"16         android:id="@+id/sb_1"17         android:max="255"    //設定最大進度為25518         android:progress="0"/>  //設定初始進度為019     <ImageView20         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     @Override13     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             @Override21             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {22 23                 iv_1.setImageAlpha(progress);24             }25 26             @Override27             public void onStartTrackingTouch(SeekBar seekBar) {28 29             }30 31             @Override32             public void onStopTrackingTouch(SeekBar seekBar) {33 34             }35         });36     }37 }

效果為:

Android實現拖動進度條改變圖片透明度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.