Android 获取图像视图重复:看起来像标题栏
我试着在我的应用程序顶部以“标题栏”的形式获取这张图片。 所以我想让它自己重复。但我有点被困在这里了 我的background.xml中有以下代码:Android 获取图像视图重复:看起来像标题栏,android,android-layout,Android,Android Layout,我试着在我的应用程序顶部以“标题栏”的形式获取这张图片。 所以我想让它自己重复。但我有点被困在这里了 我的background.xml中有以下代码: <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/topbar" android:tileMode="repeat" /&
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/topbar"
android:tileMode="repeat" />
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:background="@drawable/bgColor"
android:gravity="top"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
....
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/topbar" />
</RelativeLayout>
....
有人知道怎么做吗
谢谢。您需要将ImageView的宽度设置为
match\u parent
。那就行了。但你也可以用9patch图像来实现这一点。有关更多信息,请查看此
编辑
这是重复背景图像的布局。您需要将ImageView的src设置为background.xml。在图像父布局之间存在空格的原因是父布局具有填充。如果你把它取下来,也可以
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:gravity="top"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/background" />
</RelativeLayout>
遗憾的是,它不起作用。它使它稍微宽一点,但不是从最左边到最右边。idk为什么,但是在图像和顶部边框之间有一个空间。可悲的是,这就是我当时得到的:好吧,这对我来说很有用。你可能在那里做别的事情。这是我的XML的屏幕截图。我必须把background.xml放在每个drawable xxx目录中吗?好的,我创建了一个drawable文件夹,它以前不存在。这里是我的布局的完整列表