[英]Design Library Android
I'm using Android Design Library components, and I would like to have an image behind my ToolBar
and TabLayout
. 我正在使用Android设计库组件,并且希望在ToolBar
和TabLayout
后面有一个图像。 The image must be cropped and not fit to the size. 图像必须被裁切并且不适合尺寸。 I'm actually setting my image as android:background="@drawable/AppBarBg"
in AppBarLayout
which doesn't crop (of course) my image. 我实际上是在AppBarLayout
我的图像设置为android:background="@drawable/AppBarBg"
, AppBarLayout
该图像不会(当然)不会裁剪。 How can I crop my background image ? 如何裁剪背景图片?
<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.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/AppBarBg"
android:scaleType="centerCrop"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:orientation="horizontal"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
AppBarLayout is basically just a LinearLayout so setting a background will strech it... AppBarLayout基本上只是一个LinearLayout,因此设置背景会使其弯曲...
I think that you're looking for CollapsingToolbarLayout... Your layout structure should be like this: 我认为您正在寻找CollapsingToolbarLayout ...您的布局结构应如下所示:
AppBarLayout CollapsingToolbarLayout ImageView (this is the background which you want to centerCrop) ToolBar TabLayout etc... AppBarLayout CollapsingToolbarLayout ImageView(这是您要居中裁剪的背景)ToolBar TabLayout等...
check it out here: CollapsingToolbarLayout and TabLayout 在这里查看: CollapsingToolbarLayout和TabLayout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.