Android 如何通过单击图像按钮显示全屏图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21320294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:21:07  来源:igfitidea点击:

how to display fullscreen image by clicking imagebutton

androidimagebutton

提问by Abhinav Raja

i just have two image buttons in my layout containing two pictures which are in drawable folder. all i want is when the user clicks the image button he should see the full screen image and should be able to zoom as well.

我的布局中只有两个图像按钮,其中包含可绘制文件夹中的两张图片。我想要的是当用户单击图像按钮时,他应该看到全屏图像并且也应该能够缩放。

this is my xml:

这是我的 xml:

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


<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/piq1" 
android:layout_weight="1"
/>

<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/piq2" 
android:layout_weight="1"/>

</LinearLayout>

when the image button in clicked it should display the full image in full screen and user should be able to zoom it. please help me with the code for that.

当单击图像按钮时,它应该以全屏方式显示完整图像,并且用户应该能够对其进行缩放。请帮我写代码。

my java looks like:

我的java看起来像:

import android.app.Activity;
import android.os.Bundle;

public class Piq extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.piq);
}

采纳答案by mohammed momn

first of all , its only one idea you can make and it need you dirty your hand with this code to handle it as your case need , hope it helpful for you ,

首先,这是您唯一可以提出的一个想法,它需要您用此代码弄脏您的手才能根据您的情况处理它,希望它对您有所帮助,

here the tutorial that using full image and zooming feature you can using it

这里是使用完整图像和缩放功能的教程,您可以使用它

http://www.androidhive.info/2013/09/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures/

http://www.androidhive.info/2013/09/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures/

here the layout will be

这里的布局将是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@android:drawable/btn_radio" />

<ImageButton
    android:id="@+id/imageButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher" />

</LinearLayout>

and here the code you will use

这里是您将使用的代码

    final ImageButton img1 = (ImageButton) findViewById(R.id.imageButton1);
    final ImageButton img2 = (ImageButton) findViewById(R.id.imageButton2);

    final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);

    img1.setOnClickListener(new OnClickListener() {

        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            layout.setBackground(img1.getDrawable());

        }
    });

    img2.setOnClickListener(new OnClickListener() {

        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            layout.setBackground(img2.getDrawable());
        }
    });

回答by Abhinav Raja

this code did the trick.

这段代码成功了。

How to Zoom in/Out an ImageView(not using Canvas) in android

如何在android中放大/缩小ImageView(不使用Canvas)

little bit of adjustment is still required in it like to set the default view and also to set max and min zoom limit. but that i can do it myself now. thanx.

仍然需要进行一些调整,例如设置默认视图以及设置最大和最小缩放限制。但我现在可以自己做。谢谢。