Android編程實(shí)現(xiàn)圖片透明的方法
本文實(shí)例講述了Android編程實(shí)現(xiàn)圖片透明的方法。分享給大家供大家參考,具體如下:
今天弄了一個(gè)圖片的透明方法。
效果圖:

目錄結(jié)構(gòu)
main.xml
<?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/icon" /> <Button android:id="@+id/alpha_plus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="透明度增加" android:layout_gravity="center_horizontal" /> <Button android:id="@+id/alpha_minus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="透明度減少" android:layout_gravity="center_horizontal" /> </LinearLayout>
TOUMINGDUActivtiy
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class TOUMINGDU extends Activity {
private ImageView imageView=null;
private Button alpha_plus=null; //透明度增加
private Button alpha_minus=null; //透明度減少
private int alpha=255; //記錄ImageView的透明度
Boolean flag=true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView=(ImageView)findViewById(R.id.imageView);
alpha_plus=(Button)findViewById(R.id.alpha_plus);
alpha_minus=(Button)findViewById(R.id.alpha_minus);
alpha_plus.setOnClickListener(listener);
alpha_minus.setOnClickListener(listener);
}
private View.OnClickListener listener = new View.OnClickListener(){
public void onClick(View v) {
//加加
if(v==alpha_plus){
alpha+=10;
if(alpha>255){
alpha=255;
}
imageView.setAlpha(alpha);
}
//減減
if(v==alpha_minus){
alpha-=10;
if(alpha<0){
alpha=0;
}
imageView.setAlpha(alpha);
}
}
};
}
OK完成....
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android布局layout技巧總結(jié)》、《Android視圖View技巧總結(jié)》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android編程實(shí)現(xiàn)設(shè)置按鈕背景透明與半透明及圖片背景透明的方法
- Android實(shí)現(xiàn)的可以調(diào)整透明度的圖片查看器實(shí)例
- Android編程自定義圓角半透明Dialog的方法
- Android之沉浸式狀態(tài)欄的實(shí)現(xiàn)方法、狀態(tài)欄透明
- Android開(kāi)發(fā)中Dialog半透明背景消失
- Android設(shè)置Activity背景為透明style的簡(jiǎn)單方法(必看)
- Android Menu半透明效果的開(kāi)發(fā)實(shí)例
- Android實(shí)現(xiàn)可使用自定義透明Dialog樣式的Activity完整實(shí)例
- Android應(yīng)用中設(shè)置alpha值來(lái)制作透明與漸變效果的實(shí)例
- Android實(shí)現(xiàn)透明度可變的標(biāo)題欄效果
- Android編程實(shí)現(xiàn)popupwindow彈出后屏幕背景變成半透明效果
- Android實(shí)現(xiàn)通知欄透明的方法
相關(guān)文章
Android Studio設(shè)置繪制布局時(shí)的視圖
這篇文章介紹了Android Studio設(shè)置繪制布局時(shí)視圖的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-11-11
View Controller Transition實(shí)現(xiàn)京東加購(gòu)物車效果
這篇文章主要介紹了View Controller Transition實(shí)現(xiàn)京東加購(gòu)物車效果,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-02-02
Android Studio開(kāi)發(fā)中Gradle各種常見(jiàn)報(bào)錯(cuò)問(wèn)題解決方案
這篇文章主要為大家介紹了Android Studio開(kāi)發(fā)中Gradle各種常見(jiàn)報(bào)錯(cuò)問(wèn)題解決方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12
Android實(shí)現(xiàn)手機(jī)定位的案例代碼
今天小編就為大家分享一篇關(guān)于Android實(shí)現(xiàn)手機(jī)定位的案例代碼,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03
Android中用RxJava和ViewPager實(shí)現(xiàn)輪播圖
現(xiàn)在App中實(shí)現(xiàn)一個(gè)輪播圖已經(jīng)是很多產(chǎn)品的標(biāo)配了,這篇文章給大家詳細(xì)介紹了如何利用RxJava和ViewPager實(shí)現(xiàn)輪播圖,有需要的朋友們可以參考借鑒,下面來(lái)一起看看吧。2016-09-09
靈活使用Android中ActionBar和ViewPager切換頁(yè)面
這篇文章主要介紹了如何靈活使用Android中ActionBar和ViewPager切換頁(yè)面,感興趣的小伙伴們可以參考一下2015-12-12
Android使用RecyclerView實(shí)現(xiàn)今日頭條頻道管理功能
這篇文章主要為大家詳細(xì)介紹了Android使用RecyclerView實(shí)現(xiàn)今日頭條頻道管理功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07

