缩放图像未显示

Zoom image is not showing

我试图点击 link(如下所示),但没有任何反应!它应该打开一张可缩放的大图片

hotel.xml(这是第二个文件)

<Button
   android:id="@+id/hotel01small"
   android:layout_width="fill_parent"
   android:layout_height="45dp"
   android:gravity="center"
   android:text="Picture"
   android:textSize="10sp"
   android:textStyle="italic" />

我正在粘贴所有内容以查看它有什么问题

hotel01small.xml

<ImageView
   android:id="@+id/hotel01small"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:scaleType="matrix"
   android:src="@drawable/hotel01" />

H01.java

package com.som.balem;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class H01 extends Activity {
    ImageView imageDetail1;

 Matrix matrix = new Matrix();
 Matrix savedMatrix = new Matrix();
 PointF startPoint = new PointF();
 PointF midPoint = new PointF();
 float oldDist = 1f;
 static final int NONE = 0;
 static final int DRAG = 1;
 static final int ZOOM = 2;
 int mode = NONE;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.hotel);
  setContentView(R.layout.hotel01small);

  imageDetail1 = (ImageView) findViewById(R.id.hotel01small);

  imageDetail1.setOnTouchListener(new View.OnTouchListener()  {


   @Override
   public boolean onTouch(View v, MotionEvent event) {

    ImageView view = (ImageView) v;
    System.out.println("matrix=" + savedMatrix.toString());
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:

     savedMatrix.set(matrix);
     startPoint.set(event.getX(), event.getY());
     mode = DRAG;
     break;

    case MotionEvent.ACTION_POINTER_DOWN:

     oldDist = spacing(event);

     if (oldDist > 10f) {
      savedMatrix.set(matrix);
      midPoint(midPoint, event);
      mode = ZOOM;
     }
     break;

    case MotionEvent.ACTION_UP:

    case MotionEvent.ACTION_POINTER_UP:
     mode = NONE;

     break;

    case MotionEvent.ACTION_MOVE:
     if (mode == DRAG) {
      matrix.set(savedMatrix);
      matrix.postTranslate(event.getX() - startPoint.x,
        event.getY() - startPoint.y);
     } else if (mode == ZOOM) {
      float newDist = spacing(event);
      if (newDist > 10f) {
       matrix.set(savedMatrix);
       float scale = newDist / oldDist;
       matrix.postScale(scale, scale, midPoint.x, midPoint.y);
      }
     }
     break;

    }
    view.setImageMatrix(matrix);

    return true;
   }

   @SuppressLint("FloatMath")
   private float spacing(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return FloatMath.sqrt(x * x + y * y);
   }

   private void midPoint(PointF point, MotionEvent event) {
    float x = event.getX(0) + event.getX(1);
    float y = event.getY(0) + event.getY(1);
    point.set(x / 2, y / 2);
   }
  });   
 }
}

H01First.java

package com.som.balem;

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

public class H01First extends Activity {

    Button hotel01small;

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

Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.som.balem"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".PageOneHotel"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name=".H01"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name=".H01First"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
    </application>

</manifest>

请帮忙!

您需要为您的按钮添加一个 OnClickListener,以便在您点击它时打开第二个屏幕,否则它不会执行任何操作:

H01First.java:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class H01First extends Activity {

    Button hotel01small;

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

        hotel01small = findViewById(R.id.hotel01small);
        hotel01small.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // open up the second activity
                Intent i = new Intent(H01First.this, H01.class);
                startActivity(i);
            }           
        });
    }
}

此外,最好为所有小部件使用不同的 ID,否则可能会发生冲突并使代码更加混乱。

如果您希望首先显示 H01First Activity,请更改 Manifest.xml 以将 intent-filter 放入 HO1First 定义中:

   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.som.balem"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="8" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            </activity>
            <activity
                android:name=".PageOneHotel"
                android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            </activity>
            <activity
                android:name=".H01"
                android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            </activity>
            <activity
                android:name=".H01First"
                android:label="@string/app_name"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>

            </activity>
        </application>

    </manifest>