使用RelativeLayout中的ImageView重复Image

Usm*_*urd 27 android bitmap android-imageview android-relativelayout

我想ImageView用in 重复图像RelativeLayout.它可以是可以使用位图xml和使用TILEMODE "repeat"用RelativeLayout,因为我已经看到了在互联网上都处理事情LinearLayout.

任何帮助或提示将受到热烈欢迎.

Ani*_*udh 76

在Drawable文件夹中创建名为background的XML文件

background.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/imagename"
android:tileMode="repeat" />
Run Code Online (Sandbox Code Playgroud)

在您的相对布局中,添加上述XML作为背景

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background" />
Run Code Online (Sandbox Code Playgroud)

  • 如果将它放在ImageView中,则设置android:scaleType ="fitXY"是必要的. (10认同)

Chi*_*rag 10

是的当然,您可以使用相对布局.将它用作RelativeLayout的背景.我也在我的项目中使用它.

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:background="@drawable/top_header_bg_repeat"
        android:gravity="center">

top_header_bg_repeat.xml (in drawable folder)
----------------------------------------------

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

Set Bitmap in ImageView
----------------------   

<ImageView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/top_header_bg_repeat"
        android:scaleType="fitXY"/> 

 <ImageView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/top_header_bg_repeat"/> 
Run Code Online (Sandbox Code Playgroud)