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

时间:2014-01-23 22:04:25

标签: 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: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>

单击图像按钮时,应以全屏显示完整图像,用户应能够对其进行缩放。请帮我解释一下。

我的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);
}

2 个答案:

答案 0 :(得分:1)

首先,它只能提出一个想法,它需要你用这个代码来弄脏你的手来处理它,希望它对你有帮助,

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

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

这里的布局将是

<?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());
        }
    });

答案 1 :(得分:0)

这段代码就行了。

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

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

相关问题