Custom picture placed in Layout
Is there any way to create a custom image, and then place it into a layout you hav开发者_StackOverflow中文版e?
Yes, you can use an ImageView.
Example xml:
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"/>
Then you would just stick my_image.png
into res/drawable
.
Edit - to draw dynamically you want to subclass View
and override onDraw(Canvas) with a custom drawing method.
The other option is to load multiple images into res/drawable
and choose between them in your Java code:
ImageView image = (ImageView) findViewById(R.id.image);
image.setBitmapResource(R.id.some_image);
Just what Matthew said. Also if you meant to place the image as the layout background you can do it like
<android:background="@drawable/background">
where "background" is an image like background.png placed in the res/drawable folder.
精彩评论