您的位置:首页 > 移动开发 > Android开发

使用一个小图片tile平铺到ImageView中或Activity背景

2011-08-07 16:29 459 查看
方法两种:

首先必须在res/drawable目录下包含一个background.jpg

方法1:在res/drawable中创建一个xml文件(background_repeat.xml)

              内容为

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background"
android:tileMode="repeat"
/>


然后再Activity的xml中

<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/background_repeat">


方法2:

imageView = (ImageView)findViewById(R.id.MainA_Iv);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.background);

BitmapDrawable bd = new BitmapDrawable(bitmap);
bd.setTileModeXY(TileMode.REPEAT , TileMode.REPEAT );
imageView.setBackgroundDrawable(bd);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android layout xml
相关文章推荐