How to tile a background image in Android
来源:互联网 发布:vscode在插件 编辑:程序博客网 时间:2024/05/21 21:47
How to tile a background image in Android
After a little bit of hunting around I found this tutorial, and I thought I'd clean up the lessons within and show you how.
Here's the contents of my main.xml layout file,
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/backrepeat" android:gravity="center_horizontal" ><TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>
which is referenced in code in the standard way like this:
main);
...// (rest of onCreate method continues here..)
Now note this line:
android:background="@drawable/backrepeat"
What's going on there?
.. Glad you asked!
Here's a quick screenshot of the contents of one of my drawable folders in my project:
What is this
backrepeat.xml
?Well, here's the contents of that file here:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/scale1"
android:tileMode="repeat"
android:dither="true" />
Can you see what's going on?
Backrepeat.xml defines an instance of the BitmapDrawable class, and that class references our simple scale1.jpg, located in the drawable-hdpi folder.
Simply by adding the:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/scale1" android:tileMode="repeat" android:dither="true" />
line in bold, we are able to achieve results such as this:
Easy isn't it?
One thing to keep in mind is that you should have folders drawable-hdpi, drawable-mdpi & drawable-ldpi, you'll need to add this backrepeat.xml file and the relevant images to each of these to allow this functionality in high, medium and low dpi (dots per inch) screen sizes.
Enjoy.
- How to tile a background image in Android
- How to set background image of a component in GWTEXT
- how to select a transparent background image in ms paint.
- How to tile small texture image onto page as its background?
- How to stretch a background image of a windows form
- Android - How to have a tiled background
- How to make android app’s background image repeat.
- How to make android app's background image repeat
- how to set UITableViewCell background image
- UILabel How to set background image
- Android How to Check if the App is in Background
- How to store an image file to SQliteDB in android
- How to store an image file to SQliteDB in android
- How To Create Alternate Background In WPF?
- How to Render Image Buffer in Android NDK Native Code
- How to Render Image Buffer in Android NDK Native Code
- How to write a controller?( SDK Background)
- How to remove background of a picture?
- 算法导论——第三章——优先级队列(以堆为思想)
- ofstream建立文件问题
- 算法导论——第四章——快速排序
- HTML Script
- 处理new分配失败
- How to tile a background image in Android
- stm32学习经验
- 快速比较两字符串最大相同算法
- 算法导论——第五章——线性时间排序
- 数据绑定
- Permission Denial: starting Intent 解决办法 .
- 算法导论——第六章——中位数和顺序统计学
- 数据的绑定
- 深入理解按位异或运算符