Android 在中重复图像,并在RelativeLayout中使用ImageView
我想用Android 在中重复图像,并在RelativeLayout中使用ImageView,android,bitmap,android-imageview,android-relativelayout,Android,Bitmap,Android Imageview,Android Relativelayout,我想用ImageView在RelativeLayout中重复图像。是否可以使用位图xml并使用tilemode“repeat”和RelativeLayout,因为我在互联网上看到的东西都是处理线性布局的 任何帮助或提示都将受到热烈欢迎。是的,这是可能的。使用XML中的android:tileMode=“repeat”将重复图像定义为可绘制(位图),并将其用作相对布局的背景。用它作为你亲戚的背景。我也在我的项目中使用了它 <RelativeLayout xmlns:android="ht
ImageView
在RelativeLayout
中重复图像。是否可以使用位图xml并使用tilemode“repeat”
和RelativeLayout
,因为我在互联网上看到的东西都是处理线性布局的
任何帮助或提示都将受到热烈欢迎。是的,这是可能的。使用XML中的android:tileMode=“repeat”
将重复图像定义为可绘制(位图),并将其用作相对布局的背景。用它作为你亲戚的背景。我也在我的项目中使用了它
<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"/>
top_header_bg_repeat.xml(位于可绘图文件夹中)
----------------------------------------------
在ImageView中设置位图
----------------------
在可绘制的文件夹中创建一个名为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" />
在相对布局中添加上述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" />
在所有请求中都存在一个小问题,如果您的图像大小与布局大小相同,则图像不会调整大小,只会重复X。 对于Y重复,您只能通过编程来完成 我这样解决问题(设置重力填充) 可绘制图像背景
<?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>
和表格单元格,它的图像宽度为1px,高度为1px
等等的布局,所以现在你的图像,它就像背景,它的大小将调整为任何大小的父布局
试试看,也许能帮上忙。为了在我的情况下清除,我需要将背景图像平铺到完全大小的tablecell,并按X坐标重复(就像我可以在iOS上做的那样)。所以我像我描述的那样解决它。如果你把它放在ImageView中,设置android:scaleType=“fitXY”是必要的。