我试图将此图片作为“标题栏”显示在我的应用程序顶部。
所以我希望它重复一遍。但是我有点卡在这里。



我的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" />


这是我的布局:

<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_parent。这样就可以了。但是您也可以使用9patch图像来实现。有关更多信息,请查看此link

编辑

这是具有重复背景图像的布局。您需要将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>

关于android - 重复获取imageview:看起来像标题栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26247515/

10-11 22:29
查看更多