开发者

Custom picture placed in Layout

开发者 https://www.devze.com 2023-02-15 00:09 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号