ZoomControls控制項是一個可以縮放控制項,可以實現兩個按鈕控製圖片的大小

来源:http://www.cnblogs.com/gisoracle/archive/2016/02/24/5212520.html
-Advertisement-
Play Games

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


<?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"
    android:id="@+id/layout"
    >
    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/foot"
        />

    <ZoomControls
        android:id="@+id/zoomcontrol"
        android:layout_gravity="bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout>
package com.example.yanlei.my;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ZoomControls;

public class MainActivity extends AppCompatActivity {

    private LinearLayout llLayout;
    private ZoomControls zoomcontrols;
    private ImageView img;
    private int id = 0;
    private int displayWidth;
    private int displayHeight;
    private float scaleWidth = 1;
    private float scaleHeight = 1;
    private Bitmap bitmap;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        llLayout = (LinearLayout) findViewById(R.id.layout);
        //取得屏幕解析度大小
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        displayWidth = dm.widthPixels;
        //屏幕高度減去zoomControls的高度
        displayHeight = dm.heightPixels;
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.foot);
        img = (ImageView) findViewById(R.id.image);
        //zoom.hide();隱藏zoomControls
        //zoom.show();顯示zoomCOntrols

        zoomcontrols = (ZoomControls) findViewById(R.id.zoomcontrol);
        img = (ImageView) findViewById(R.id.image);
        zoomcontrols.setIsZoomInEnabled(true);
        zoomcontrols.setIsZoomOutEnabled(true);
        //圖片放大
        zoomcontrols.setOnZoomInClickListener(new OnClickListener() {
            public void onClick(View v) {
                int bmpWidth = bitmap.getWidth();
                int bmpHeight = bitmap.getHeight();
                //設置圖片放大但比例
                double scale = 1.25;
                //計算這次要放大的比例
                scaleWidth = (float) (scaleWidth * scale);
                scaleHeight = (float) (scaleHeight * scale);
                //產生新的大小但Bitmap對象
                Matrix matrix = new Matrix();
                matrix.postScale(scaleWidth, scaleHeight);
                Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
                img.setImageBitmap(resizeBmp);

            }
        });
        //圖片減小
        zoomcontrols.setOnZoomOutClickListener(new OnClickListener() {

            public void onClick(View v) {
                int bmpWidth = bitmap.getWidth();
                int bmpHeight = bitmap.getHeight();
                //設置圖片放大但比例
                double scale = 0.8;
                //計算這次要放大的比例
                scaleWidth = (float) (scaleWidth * scale);
                scaleHeight = (float) (scaleHeight * scale);
                //產生新的大小但Bitmap對象
                Matrix matrix = new Matrix();
                matrix.postScale(scaleWidth, scaleHeight);
                Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true);
                img.setImageBitmap(resizeBmp);
            }

        });
    }
}

參考:http://blog.csdn.net/jianghuiquan/article/details/8350538


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 簡介:UIPickerView是一個選擇器控制項,它比UIDatePicker更加通用,它可以生成單列的選擇器,也可生成多列的選擇器,而且開發者完全可以自定義選擇項的外觀,因此用法非常靈活。UIPickerView直接繼承了UIView,沒有繼承UIControl,因此,它不能像UIControl那樣
  • 一、問題在哪裡? textview顯示長文字時會進行自動折行,如果遇到一些特殊情況,自動折行會杯具成這個樣子: 上述特殊情況包括: 1)全形/半形符號混排(一般是數字、字母、漢字混排) 2)全形/半形標點符號出現在行首時,該標點符號會連同其前一個字元跳到下一行 3)英文單詞不能被折成兩行 4)...
  • 這段時間對視頻開發進行了一些瞭解,在這裡和大家分享一下我自己覺得學習步驟和資料,希望對那些對視頻感興趣的朋友有些幫助。 一、iOS系統自帶播放器 要瞭解iOS視頻開發,首先我們從系統自帶的播放器說起,一、我們可以直接播放視頻,看到效果,不然搞了半天還播放不了視頻,會讓大家失去興趣。二、其實對於很多需
  • 先看這段源碼介紹: /** * Called when a view created by this adapter has been detached from its window. * * <p>Becoming detached from the window is not necessar
  • 我在將以前在Eclipse中寫的項目import到android studio中後,出現了 AAPT err(Facade for 157667509): libpng error: Not a PNG file 錯誤,提示信息顯示圖片非PNG格式。 解決方法: 在studio中依次點開每個尾碼名為
  • 自己總結的功能: 添加xml中的中文到string.xml中 extract android string= Alt + Enter來調用 ----常用快捷鍵 1.Ctrl+E,可以顯示最近編輯的文件列表 2.Shift+Click可以關閉文件 3.Ctrl+[或]可以跳到大括弧的開頭結尾 4.Ct
  • 參考:http://blog.csdn.net/jianghuiquan/article/details/8569252 在Android平臺上,集成了一個嵌入式關係型資料庫—SQLite。以SQLite是一款輕型資料庫:SQLite3支持 NULL、INTEGER、REAL(浮點數字)、TEXT(
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...