最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實現(xiàn)的可以調整透明度的圖片查看器實例

 更新時間:2014年07月22日 11:48:22   投稿:shichen2014  
這篇文章主要介紹了Android實現(xiàn)的可以調整透明度的圖片查看器,需要的朋友可以參考下

本文以實例講解了基于Android的可以調整透明度的圖片查看器實現(xiàn)方法,具體如下:

main.xml部分代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="增大透明度" />

    <Button
      android:id="@+id/button2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="減小透明度" />

    <Button
      android:id="@+id/button3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="下一張" />
  </LinearLayout>
  <!-- 定義顯示整體圖片的ImageView -->

  <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#0000ff"
    android:scaleType="fitCenter"
    android:src="@drawable/shuangta" />
  <!-- 定義顯示局部圖片的ImageView -->

  <ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="#0000ff" />

</LinearLayout>

java部分代碼為:

package android.demo;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;

public class AndroidDemo5Activity extends Activity {
  // 定義一個訪問圖片的數組
  int[] images = new int[] { R.drawable.lijiang, R.drawable.qiao,
      R.drawable.shuangta, R.drawable.shui, R.drawable.xiangbi,
      R.drawable.ic_launcher, };
  // 定義當前顯示的圖片
  int currentImage = 2;
  // 定義圖片的初始透明度
  private int alpha = 255;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final Button plusButton = (Button) findViewById(R.id.button1);
    final Button minuxButton = (Button) findViewById(R.id.button2);
    final Button nextButton = (Button) findViewById(R.id.button3);

    final ImageView imageview1 = (ImageView) findViewById(R.id.imageView1);
    final ImageView imageview2 = (ImageView) findViewById(R.id.imageView2);

    // 定義查看下一張圖片的時間監(jiān)聽器
    nextButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        if (currentImage >= 5) {
          currentImage = -1;
        }
        BitmapDrawable bitmap = (BitmapDrawable) imageview1
            .getDrawable();
        // 如果圖片還沒有回收,先強制回收圖片
        if (!bitmap.getBitmap().isRecycled()) {
          bitmap.getBitmap().recycle();
        }
        // 改變ImageView的圖片
        imageview1.setImageBitmap(BitmapFactory.decodeResource(
            getResources(), images[++currentImage]));
      }
    });

    // 定義改變圖片透明度的方法
    OnClickListener listener = new OnClickListener() {

      @Override
      public void onClick(View v) {
        if (v == plusButton) {
          alpha += 20;
        }
        if (v == minuxButton) {
          alpha -= 20;
        }
        if (alpha > 255) {
          alpha = 255;
        }
        if (alpha <= 0) {
          alpha = 0;
        }
        // 改變圖片的透明度
        imageview1.setAlpha(alpha);

      }
    };

    // 為2個按鈕添加監(jiān)聽器
    plusButton.setOnClickListener(listener);
    minuxButton.setOnClickListener(listener);
    imageview1.setOnTouchListener(new OnTouchListener() {

      @Override
      public boolean onTouch(View arg0, MotionEvent arg1) {
        // TODO Auto-generated method stub
        BitmapDrawable bitmapDeaw = (BitmapDrawable) imageview1
            .getDrawable();
        // 獲取第一個圖片顯示框中的位圖
        Bitmap bitmap = bitmapDeaw.getBitmap();
        double scale = bitmap.getWidth();
        // 或許需要顯示圖片的開始點
        int x = (int) (arg1.getX() * scale);
        int y = (int) (arg1.getY() * scale);
        if (x + 120 > bitmap.getWidth()) {
          x = bitmap.getWidth() - 120;
        }
        if (y + 120 > bitmap.getHeight()) {
          y = bitmap.getHeight() - 120;
        }

        // 顯示圖片的指定區(qū)域
        imageview2.setImageBitmap(Bitmap.createBitmap(bitmap, x, y,
            120, 120));
        imageview2.setAlpha(alpha);
        return false;
      }
    });
  }

}

運行效果圖如下:

相關文章

  • Android批量插入數據到SQLite數據庫的方法

    Android批量插入數據到SQLite數據庫的方法

    這篇文章主要為大家詳細介紹了Android批量插入數據到SQLite數據庫的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android中AutoCompleteTextView與TextWatcher結合小實例

    Android中AutoCompleteTextView與TextWatcher結合小實例

    這篇文章主要為大家詳細介紹了Android中AutoCompleteTextView與TextWatcher結合的小實例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android APP存活檢測方式

    Android APP存活檢測方式

    這篇文章主要介紹了Android APP存活檢測方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Android?hid發(fā)送apdu格式數據示例詳解

    Android?hid發(fā)送apdu格式數據示例詳解

    這篇文章主要介紹了Android?hid發(fā)送apdu格式數據,在?Android?中,如果你想通過?HID(Human?Interface?Device)發(fā)送?APDU?格式的數據,通常會涉及?USB?HID?設備或藍牙?HID?設備,本文給大家講解的非常詳細,需要的朋友可以參考下
    2023-08-08
  • Android ViewPager自定義輪播圖并解決播放沖突

    Android ViewPager自定義輪播圖并解決播放沖突

    這篇文章主要為大家詳細介紹了Android ViewPager自定義輪播圖并解決播放沖突,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android音視頻開發(fā)之VideoView使用指南

    Android音視頻開發(fā)之VideoView使用指南

    VideoView組件內部同樣是使用MediaPlayer+SurfaceView的形式控制MediaPlayer對視頻文件進行播放,本文就來詳細講講它的使用方法,需要的可以參考一下
    2022-04-04
  • 打造酷炫的AndroidStudio插件

    打造酷炫的AndroidStudio插件

    這篇文章主要為大家詳細介紹了如何打造酷炫的AndroidStudio插件,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Android View實現(xiàn)圓形進度條

    Android View實現(xiàn)圓形進度條

    這篇文章主要為大家詳細介紹了Android View實現(xiàn)圓形進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • 如何給Android中的按鈕添加圖片功能

    如何給Android中的按鈕添加圖片功能

    這篇文章主要介紹了Android中的按鈕加圖片功能,代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • Android中極簡的js與java的交互庫(SimpleJavaJsBridge)

    Android中極簡的js與java的交互庫(SimpleJavaJsBridge)

    本文主要介紹了Android中極簡的js與java的交互庫--SimpleJavaJsBridge,它可以讓js與java之間的通信更簡單。 具有很好的參考價值,下面跟著小編一起來看下吧
    2017-01-01

最新評論

金塔县| 青神县| 枝江市| 井研县| 城步| 海伦市| 衡阳县| 陇西县| 琼结县| 新竹市| 当涂县| 东辽县| 邳州市| 周宁县| 邹平县| 新巴尔虎右旗| 汾西县| 富阳市| 黎城县| 伊春市| 南皮县| 渭南市| 南岸区| 泰和县| 珲春市| 大方县| 柘城县| 襄垣县| 隆德县| 江油市| 霍山县| 宝鸡市| 新野县| 罗甸县| 宜春市| 若尔盖县| 罗田县| 白城市| 麻城市| 武威市| 昆明市|