缩放图像不显示缩放、图像

2023-09-03 22:08:13 作者:还可以。

我试图点击链接(如下图),但没有任何反应!它应该开大的变焦,能够图片

I am trying to click on the link (as below) but nothing happens! It should open big an zoom-able picture

hotel.xml(这是第二文件)

hotel.xml (this is a second file)

<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" />

我贴我的一切,看看有什么地方错了。

i'm pasting everything to see what's wrong with it

hotel01small.xml

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

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

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.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添加到您的按钮,打开第二个屏幕,当你点击它,否则它不会做任何事情:

You need to add an OnClickListener to your button to open the second screen when you tap it, otherwise it won't do anything:

H01First.java:

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的所有部件是一个好主意,否则你可以得到冲突,它使code更加混乱。

Also, it's a good idea to use different ids for all your widgets, otherwise you can get conflicts and it makes the code more confusing.

如果您希望H01First活动首先显示,改变你的Manifest.xml把意图过滤器的HO1First定义中:

If you want the H01First Activity to display first, change your Manifest.xml to put the intent-filter inside the HO1First definition:

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