0

私は最初の Android プロジェクト/最初の Java プロジェクトを構築しています。ユーザーがクリックできる複数のボタンが上にある画像を描画しようとしています。ただし、ボタンをズームインすると、希望どおりに拡大され、背景の画像との相対位置が維持されますが、onClickListener に応答しなくなります。

XML コード

<FrameLayout
    android:id="@+id/DeckLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:gravity="center_horizontal" >

    <!-- <CustomDrawableView android:layout_height="fill_parent"
               android:layout_width="fill_parent"
              />  -->

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="420dp"
        android:clickable="false"
        android:scaleType="fitCenter"
        android:src="@drawable/deck12" />

    <Button
        android:id="@+id/QM2_12002"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:gravity="center"/>


</FrameLayout>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal" >
    <Button
            android:id="@+id/zoom_in"
            android:layout_width="102dp"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/zoom_in" />
</FrameLayout>
</LinearLayout>

Java コード

package com.sgs.hotelguru;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PointF;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;




public class MapsExample extends Activity {

    View mainView = null;
    final float Zoom_max = 5f;
    private static final String TAG = "Die Karte";

     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_maps_example);
      mainView =findViewById(R.id.DeckLayout);

      //Button buttonZoomOut = (Button)findViewById(R.id.zoom_out);
      //Button buttonNormal = (Button)findViewById(R.id.reset);
      Button buttonZoomIn = (Button)findViewById(R.id.zoom_in);

      /*buttonZoomOut.setOnClickListener(new OnClickListener() {

       @Override
       public void onClick(View v) {
        zoom(0.5f,0.5f,new PointF(0,0));    
       }
      });
      buttonNormal.setOnClickListener(new OnClickListener() {

       @Override
       public void onClick(View v) {
        zoom(1f,1f,new PointF(0,0));  
       }
      });*/
      buttonZoomIn.setOnClickListener(new OnClickListener() {

       @Override
       public void onClick(View v) {
        zoom(new PointF(0,0));   
       }
      });
      mainView.post(new Runnable() {
          // Post in the parent's message queue to make sure the parent
          // lays out its children before you call getHitRect()
          @Override
          public void run() {
              // The bounds for the delegate view (an ImageButton
              // in this example)
              Button QM2_12002 = (Button)findViewById(R.id.QM2_12002);
              QM2_12002.setX(300);
              QM2_12002.setY(400);
              QM2_12002.setEnabled(true);
              QM2_12002.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      Toast.makeText(MapsExample.this, 
                              "YOU CLICKY THE BUTTON YAY!", 
                              Toast.LENGTH_SHORT).show();
                  }
              });

          }
      });
  }


     /** zooming is done from here */
     public void zoom(PointF pivot){
      mainView.setPivotX(pivot.x);
      mainView.setPivotY(pivot.y);  
      float workScaleX = mainView.getScaleX();
      float workScaleY = mainView.getScaleY();
      if(workScaleX<Zoom_max)
      {
      mainView.setScaleX(workScaleX+1f);
      mainView.setScaleY(workScaleY+1f);  
      }
     }

    }
4

1 に答える 1

0
// try this
public class MainActivity extends Activity {

    View mainView;
    Button QM2_12002;
    Button buttonZoomIn;
    final float Zoom_max = 5f;
    private static final String TAG = "Die Karte";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps_example);
        mainView =findViewById(R.id.DeckLayout);

        //Button buttonZoomOut = (Button)findViewById(R.id.zoom_out);
        //Button buttonNormal = (Button)findViewById(R.id.reset);
        buttonZoomIn = (Button)findViewById(R.id.zoom_in);
        QM2_12002 = (Button)findViewById(R.id.QM2_12002);

      /*buttonZoomOut.setOnClickListener(new OnClickListener() {

       @Override
       public void onClick(View v) {
        zoom(0.5f,0.5f,new PointF(0,0));
       }
      });
      buttonNormal.setOnClickListener(new OnClickListener() {

       @Override
       public void onClick(View v) {
        zoom(1f,1f,new PointF(0,0));
       }
      });*/
        buttonZoomIn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                zoom(new PointF(0,0));
            }
        });
        QM2_12002.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,
                        "YOU CLICKY THE BUTTON YAY!",
                        Toast.LENGTH_SHORT).show();
            }
        });
        mainView.post(new Runnable() {
            // Post in the parent's message queue to make sure the parent
            // lays out its children before you call getHitRect()
            @Override
            public void run() {
                // The bounds for the delegate view (an ImageButton
                // in this example)
                QM2_12002.setX(300);
                QM2_12002.setY(400);
                QM2_12002.setEnabled(true);
            }
        });
    }


    /** zooming is done from here */
    public void zoom(PointF pivot){
        mainView.setPivotX(pivot.x);
        mainView.setPivotY(pivot.y);
        float workScaleX = mainView.getScaleX();
        float workScaleY = mainView.getScaleY();
        if(workScaleX<Zoom_max)
        {
            mainView.setScaleX(workScaleX+1f);
            mainView.setScaleY(workScaleY+1f);
        }
    }
}
于 2013-10-11T04:50:03.810 に答える