android - 获取 imageview 重复 : looks like titlebar

标签 android android-layout

我尝试将此图片作为“标题栏”放在我的应用程序的顶部。 所以我希望它自己重复。但我有点卡在这里。

enter image description here

我的 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 重复 : looks like titlebar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26247515/

相关文章:

android - 无法解析导入 android.app.FragmentManager

Android - 使用 SYSTEM_OVERLAY 改变触摸事件

android - 带有文本和按钮的 float ImageView

android - 如何使用 android-actionBar 启动ActivityForResult?

android - 良好的 Android 用户界面设计 - 何时添加明确的取消按钮?

java - 如何将框架布局的 y 值设置为屏幕高度的 3/4?

android - 如何在整个应用程序中保持相同的背景?

android - LinearLayout 无法正确对齐

android - 在第一个微调器 android 中选择时如何更改第二个微调器数组

android - 使用 DialogFragment 和 Android Annotations 设置日期