Android 在RelativeLayout 中使用ImageView 重复输入图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12262735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Repeat Image in with ImageView in RelativeLayout
提问by Usman Kurd
I want to repeat the image with ImageView
with in RelativeLayout
. Can it be possible to use the Bitmap xml and use tilemode "repeat"
with RelativeLayout
, because what I have seen things on Internet they all dealing with LinearLayout
.
我想ImageView
用 in重复图像RelativeLayout
。是否可以使用Bitmap xml并使用tilemode "repeat"
with RelativeLayout
,因为我在Internet上看到的东西都在处理LinearLayout
。
Any help or tip will be warmly welcomed.
任何帮助或提示将受到热烈欢迎。
回答by Anirudh
Create an XML file named background in Drawablefolder
在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" />
In your Relative Layout add the above XML as background
在您的相对布局中添加上述 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" />
回答by Chirag
Yes of Course, You can use it with relative layout. Use it as background of your RelativeLayout. I also used it in my project.
是的,当然,您可以将它与相对布局一起使用。将其用作您的 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"/>
回答by waqaslam
Yes, its possible. Define your repeating image as Drawable (bitmap)
with android:tileMode="repeat"
in XML and use it as background of your RelativeLayout
.
是的,这是可能的。定义你的重复形象Drawable (bitmap)
与android:tileMode="repeat"
XML和使用它作为您的背景RelativeLayout
。
回答by Dmitry Nelepov
In all requests exists one small problem if you image will be great and smaller what size your layout, image will not resize, only repeat by X. For repeat by Y you can do it only programmly.
在所有请求中都存在一个小问题,如果您的图像会更大更小您的布局大小,图像不会调整大小,只能重复 X。对于重复 Y,您只能通过编程来完成。
I solve my problem like this (set gravity fill)
我这样解决我的问题(设置重力填充)
drawable bg for image
图像的可绘制背景
<?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" />
and on layout
和布局
<?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>
And table_cells_bg_img it's image with width=1px and height = 1px
而 table_cells_bg_img 它的图像宽度= 1px,高度= 1px
and etc of layout, so now your image it's like background and it's will resized for any size of parent layout
等等布局,所以现在你的图像就像背景一样,它会为任何大小的父布局调整大小
Try, maybe help. To be cleared in my case i need tiled background image to full size of tablecell repeated by X coordinate (like i can do it on iOS). So i solve it like i describe.
试试吧,也许有帮助。要在我的情况下清除,我需要将背景图像平铺到按 X 坐标重复的全尺寸表格单元格(就像我可以在 iOS 上做的那样)。所以我像我描述的那样解决它。