简体   繁体   中英

Android: How to use two custom views in an Activity?

The ZoomInZoomOut extends imageView and allows the user to drag around and zoom in the image using gestures, the DrawView forms a resizeable circle, and this is what I want to show up when the user presses the button

Here's the code implementing what I have...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_display);
    Intent intent = getIntent();
    String path = getIntent().getStringExtra(ImageDisplayActivity.KEY_PATH);
    final Button button = (Button) findViewById(R.id.button1);
    try {
        java.io.FileInputStream in = this.openFileInput(path);
        bitmap = BitmapFactory.decodeStream(in);
        bitmap = bitmap.copy(bitmap.getConfig(), true);
        touch = (ZoomInZoomOut)findViewById(R.id.IMAGEID);
        touch = arrangeImageView(touch);
        touch.setImageBitmap(bitmap);
        in.close();


    } catch (Exception e) {
        e.printStackTrace();
    }
}
public void sendMessage(View view) {
    // Do something in response to button click
    shape = (DrawView)findViewById(R.id.IMAGEID2);
}

The XML

<com.commonsware.android.test1.ZoomInZoomOut
    android:id="@+id/IMAGEID"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

<com.commonsware.android.test1.DrawView
    android:id="@+id/IMAGEID2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="AddCircle"
    android:id="@+id/button1"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:onClick="sendMessage"/>

第一个VISIBLE ,另一个INVISIBLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM