繁体   English   中英

Android:如何在一个Activity中使用两个自定义视图?

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

ZoomInZoomOut扩展了imageView并允许用户使用手势在图像中拖动和放大,DrawView形成了一个可调整大小的圆圈,这就是我想要在用户按下按钮时显示的内容

这是实现我所拥有的代码...

@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);
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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