7, Android button how to tile a picture?

Source: Internet
Author: User

I want to achieve the effect: But the designer gives this:.

The first thing I think about is that this is like the Windows computer settings wallpaper has what stretch, adaptive, tile and other types, this should be the legendary tile bar.

Then we know that an ordinary button, set his background, is nothing more than setbackgrounddrawable/resource/color these kinds of methods can be called in the method can not be set to tile.

What do we do?

1, the big Baidu search "Android Tile", search the following two key links:

Android Tile background (3 tiling methods)

The relationship between the "Android" ScaleType property and the display of the picture in Imagview (the alignment of the picture in ImageView)

2, the Dry goods

1             New_button.setx ((float) x);2 new_button.sety ((float) y);//Set the position of the button3             4 Resources res = splash.contextTools.getResources ();5 drawable drawable = res.getdrawable (r.drawable.split_line);//Get Picture Resources6 bitmapdrawable bd = (bitmapdrawable) drawable;7 Bd.settilemodey (tilemode.repeat);//This is the set tile9 new_button.setbackgrounddrawable (BD);//Background set to buttonTen              One int width = Commonutils.px2dip (Splash.contexttools, n); A int height = +; the  - relativelayout.layoutparams LP = new Relativelayout.layoutparams (width,height); - Rl.addview (View) NEW_BUTTON,LP);//Add button to layout -             

3. Explanation

To achieve a tiling effect, there are 3 key points:

①bitmapdrawable

②bitmapdrawable the corresponding method Settilemodey

③ from local to picture resources

Why this is the 3 key points, in fact the reason is very simple: ① you want to set the tile, you must get the picture to tile ② to support tiling, we need to use Bitmapdrawable③ to set the tile, we need to know the interface set

Well, I think the explanation is over, I hope to help you. If in doubt, please refer to the above two hyperlinks, you can also leave a message to me.

7, Android button how to tile a picture?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.