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