我想在RelativeLayout
中使用ImageView
来重复图片。是否可以使用位图XML并使用平铺模式"repeat"
与RelativeLayout
,因为我在互联网上看到的所有东西都涉及LinearLayout
。
欢迎任何帮助或提示。
我想在RelativeLayout
中使用ImageView
来重复图片。是否可以使用位图XML并使用平铺模式"repeat"
与RelativeLayout
,因为我在互联网上看到的所有东西都涉及LinearLayout
。
欢迎任何帮助或提示。
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/imagename"
android:tileMode="repeat" />
在你的相对布局中添加上面的XML代码作为背景
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:background="@drawable/background" />
<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"/>
Drawable(位图)
,并使用android:tileMode="repeat"
作为RelativeLayout
的背景。<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/table_cells_bg_img"
android:tileMode="repeat" android:gravity="fill" />
并且在布局上
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="@dimen/table_cell_height">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="@dimen/table_cell_height"
android:scaleType="fitXY"
android:src="@drawable/table_cells_bg"/>
<TextView
android:id="@+id/txtActivityTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/avatarImage"
android:text="TextView"
android:textColor="@color/white"
android:textSize="@dimen/font_size_middle" />
</RelativeLayout>
table_cells_bg_img是一张宽度为1像素,高度为1像素的图片。
在布局等方面,现在您的图片就像背景一样,并且会根据父布局的任何大小进行调整。
尝试一下,也许有帮助。在我的情况下,我需要平铺的背景图像来填满表格单元格的完整大小,并通过X坐标重复(就像我可以在iOS上做的那样)。所以我按照我描述的方式解决了这个问题。