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

Android 如何通过单击imagebutton显示全屏图像,android,imagebutton,Android,Imagebutton,我只是在我的布局中有两个图像按钮,其中包含两张可绘制文件夹中的图片。我想要的是,当用户单击图像按钮时,他应该可以看到全屏图像,并且应该能够进行缩放 这是我的xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:la

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

这是我的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>

首先,这是你唯一能想到的一个办法,需要你用这段代码来处理,希望它能对你有所帮助

这里的教程介绍了如何使用完整图像和缩放功能

这里是布局图

<?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>

这段代码成功了


它仍然需要一些调整,比如设置默认视图,以及设置最大和最小缩放限制。但我现在可以自己做了。thanx.

代码的其余部分在哪里?什么代码?您还需要什么?我不知道如何显示onclick listener for imagebutton以显示全屏图像我想您可以在代码中尝试并为我们显示它OK,当用户按下图像按钮时,您可以删除图像src并将布局背景与所选按钮图像一起放置。在这种情况下,它将占据整个屏幕。这将全屏显示图像,但图像按钮也可见。我也不能放大。我知道从哪里开始了。但我真正想要的是图片的显示方式与画廊照片中的显示方式相同。您希望如何进行缩放,如果你想制作一些像gallery这样的东西,为什么需要制作图像按钮而不是实现gallery?这是可能的吗?仅显示两幅图像,就像在画廊中显示的一样。缩放应该像收缩缩放一样。同时双击(放大)和再次双击(恢复正常)是的,我明白了,你需要使用手势来缩放图像,我将在我编辑的回答中为你提供示例我之前看过该教程。。看起来有点复杂。我只需要2张图片。我是否需要为2张图片编写完整的代码?
<?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>
    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());
        }
    });