Android实现的可以调整透明度的图片查看器实例_Android

本文以实例讲解了基于Android的可以调整透明度的图片查看器实现方法,具体如下:

 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);

    // 定义查看下一张图片的时间监听器
    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个按钮添加监听器
    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;
        }

        // 显示图片的指定区域
        imageview2.setImageBitmap(Bitmap.createBitmap(bitmap, x, y,
            120, 120));
        imageview2.setAlpha(alpha);
        return false;
      }
    });
  }

}

运行效果图如下:

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索android
, 图片
, 透明度
, 查看器
调整
ppt调整图片透明度、调整图片透明度、ps调整图片透明度、ps怎么调整透明度、ps如何调整透明度,以便于您获取更多的相关知识。

时间: 2024-08-22 14:11:20

Android实现的可以调整透明度的图片查看器实例_Android的相关文章

Android实现的可以调整透明度的图片查看器实例

本文以实例讲解了基于Android的可以调整透明度的图片查看器实现方法,具体如下: main.xml部分代码如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" a

Android编程实现网络图片查看器和网页源码查看器实例_Android

本文实例讲述了Android编程实现网络图片查看器和网页源码查看器.分享给大家供大家参考,具体如下: 网络图片查看器 清单文加入网络访问权限: <!-- 访问internet权限 --> <uses-permission android:name="android.permission.INTERNET"/> 界面如下:   示例: public class MainActivity extends Activity { private EditText ima

android 类qq空间图片查看器。出现好多错误 求大神帮忙。小女涉入甚浅。

问题描述 android 类qq空间图片查看器.出现好多错误 求大神帮忙.小女涉入甚浅. 11-20 11:26:39.629: E/AndroidRuntime(1136): FATAL EXCEPTION: main 11-20 11:26:39.629: E/AndroidRuntime(1136): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.desktop/co

android类似于QQ聊天时双击打开图片查看的效果如何实现

问题描述 android类似于QQ聊天时双击打开图片查看的效果如何实现 想做个图片查看的插件,就像QQ聊天时,对方发了一张图片,可以双击打开,可以用滚轮放大缩小,可以拖动.哪位朋友有相关经验的,请给个Demo,不胜感谢 解决方案 我觉得你应该看看android手势!

Android 简单的图片查看器源码实现

本文介绍了Android 简单的图片查看器源码实现,分享给大家,具体如下: public class MainActivity extends Activity { private EditText et_path; private ImageView iv; //创建handler 对象 // private Handler handler = new Handler(){ // // //处理消息 // public void handleMessage(android.os.Message

基于touch.js手势库+zepto.js插件开发图片查看器(滑动、缩放、双击缩放)_javascript技巧

最近由于公司项目需要图片查看器,网上搜了一圈,感觉资料很少,所以决定基于百度的touch.js手势库+zepto.js自己写了一个小插件,实现了左右滑动,双指缩放,双击缩放功能,基本使用还行,但是有时候还是不太顺畅,后续会慢慢完善:写的不好的地方望各位能够给出好的建议,谢谢! 源码地址:https://github.com/GLwen/molong_photoSwipe.git 演示:http://runjs.cn/detail/iceaaogh molong.css *{padding:0;m

windows图片查看器,受组策略限制的问题

问题描述 windows图片查看器,受组策略限制的问题 组策略设为白名单,准许rundll32.exe运行,图片从网页上下载到电脑打开正常.但在下载时直接选打开,就会提示受到策略限制.从进程记录器来看确实是调用rundll32.exe求解决啊 解决方案 感谢楼上 我解决了 把shimgvw.dll加到白名单里就可以了原帖地址 http://bbs.csdn.net/topics/390235767 解决方案二: 你是否设置了别的组策略和安全选项,找一台默认安装的系统试验下. 解决方案三: 下载直

Dreamweaver基础视频教程14 Flash图片查看器

dreamweaver|教程|视频教程 http://www.ty502.com/jiaochen/Dreamweaver基础视频教程14 Flash图片查看器.swf

基于jQuery的一个简单的图片查看器

项目中自己diy了一个图片查看器.因为初始代码不是自己的,只是在上面改了一下也没有弄的很漂亮.等以后有时间了在重写一下样式和封装,作为备用的只是积累吧.如果有童鞋有用到,完全可以在此基础上改,比较容易,代码也比较简单 图片查看器主要有几个功能: 1.显示图片和图片信息(图片名称.发布者等等) 2.切换图片 3.关闭图片查看器   初始化接口函数pictureViewer.init: function(picInfos,tapNumber,isBig) picInfos: 传入图片组信息,必须,格