单击ImageView的特定部分

时间:2013-09-03 02:00:52

标签: imageview zoom imagebutton

我希望能够触摸ImageView的特定部分并显示祝酒词。

这是我的xml文件“dessintest.xml”:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    android:id="@+id/relative1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <ImageView
    android:id="@+id/imageview1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/dessin1"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    >
    </ImageView>

    <ImageButton
        android:id="@+id/imageButton1"
        android:background="#00000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/image" />

    </RelativeLayout>

然后这是我的主文件“DessinTest.java”:

public class DessinTest extends Activity {

    ImageButton imageButton;

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

        addListenerOnButton();

        Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.dessin1);
        TouchImageView touch = new TouchImageView(this);
        touch.setImageBitmap(bm);
        touch.setMaxZoom(4f); //change the max level of zoom, default is 3f
        setContentView(touch);     

    }

    public void addListenerOnButton() {

        imageButton = (ImageButton) findViewById(R.id.imageButton1);

        imageButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

               Toast.makeText(DessinTest.this,"Click !", Toast.LENGTH_SHORT).show();

            }

        });
    }
}

当我尝试时,我可以缩放ImageView但我看不到ImageButton。 当我删除这段代码(用于缩放我的ImageView的代码)时:

 Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.dessin1);
        TouchImageView touch = new TouchImageView(this);
        touch.setImageBitmap(bm);
        touch.setMaxZoom(4f); //change the max level of zoom, default is 3f
        setContentView(touch);

它正常工作,我可以看到ImageButton并点击它。

我想要的是兼具功能,点击和缩放。

谢谢!

1 个答案:

答案 0 :(得分:0)

好的我使用此示例解决了我的问题:

https://github.com/chrisbanes/PhotoView/blob/master/sample/src/uk/co/senab/photoview/sample/SimpleSampleActivity.java

我现在可以缩放和触摸/检测屏幕的特定部分。它运作得很好!