Android Implementation drag progress bar change picture transparency

Source: Internet
Author: User

Layout file:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns: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"Ten Tools:context= "Com.hanqi.testapp2.PractiseActivity" One android:orientation= "vertical"> A  -     <SeekBar -         Android:layout_width= "Match_parent" the Android:layout_height= "Wrap_content" - Android:id= "@+id/sb_1" - Android:max= "255" //Set maximum progress to 255  - android:progress= "0"/> //Set initial progress to 0  +     <ImageView -         Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" A android:src= "@drawable/f4" at Android:id= "@+id/iv_1"/> - </LinearLayout>

Java Class Code:

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 Ten SeekBar sb_1; One ImageView iv_1; A @Override - protected void OnCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); the Setcontentview (r.layout.activity_practise); - sb_1 = (SeekBar) Findviewbyid (r.id.sb_1); - iv_1 = (ImageView) Findviewbyid (r.id.iv_1); - iv_1.setimagealpha (0); //This step is to set the start of the picture is transparent, do not set the picture will be displayed at the beginning of the run  + Sb_1.setonseekbarchangelistener (New Seekbar.onseekbarchangelistener () { - @Override + Public void Onprogresschanged (SeekBar SeekBar, int progress, Boolean fromuser) { A  at Iv_1.setimagealpha (progress); -             } -  - @Override - Public void Onstarttrackingtouch (SeekBar SeekBar) { -  in             } -  to @Override + Public void Onstoptrackingtouch (SeekBar SeekBar) { -  the             } *         }); $     }Panax Notoginseng}

The effect is:

Android Implementation drag progress bar change picture transparency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.