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?