Android AppBar背景填充整个屏幕
我的应用程序包含一个AppBar,我希望它有一个背景图像。因此,我将图像设置为Android AppBar背景填充整个屏幕,android,Android,我的应用程序包含一个AppBar,我希望它有一个背景图像。因此,我将图像设置为AppBarLayout:background,但是图像不适合条的大小,而是填充整个屏幕。我希望它只到达选项卡视图的末尾,这样就不会影响下面的内容 我的xml: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.and
AppBarLayout:background
,但是图像不适合条的大小,而是填充整个屏幕。我希望它只到达选项卡视图的末尾,这样就不会影响下面的内容
我的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="@drawable/dunkvert"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="TextView" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TabItem
android:id="@+id/tabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A" />
<android.support.design.widget.TabItem
android:id="@+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
工具栏实际上代表您的工具栏,请尝试在框架布局中向其添加图像视图,以便与文本视图一起使用:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="TextView" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:src="@drawable/dunkvert" />
</FrameLayout>
</android.support.v7.widget.Toolbar>
或者简单地将工具栏的背景设置为所需的图像
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/dunkvert"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="TextView" />
</android.support.v7.widget.Toolbar>
第二种解决方案似乎不错,但背景不在选项卡视图上,而是在上面。你能告诉我怎么做吗?你想让它同时到达工具栏和表格布局吗?相同的背景,就像在相同图像的延续中一样?是的,确切地说,选项卡和工具栏之间只有一个图像,没有边缘。按照当前布局,您不能这样做,它们有不同的父视图。为了让他们共享一个背景,他们需要共享同一个父对象,而您只需在父对象中添加背景:/