android-constraintLayout如何将提升添加到粘性工具栏?
我已经创建了constraintLayout,但我使用的工具栏没有阴影高程。我看不到任何影子。以下是我到目前为止所拥有的图像: 我想把绿色部分抬高一点,加上一点阴影。您知道物料标题的方式。因此,当我滚动recyclerview时,它会在标题下显示它的Ogging。现在很标准 以下是我目前的代码:android-constraintLayout如何将提升添加到粘性工具栏?,android,toolbar,android-constraintlayout,Android,Toolbar,Android Constraintlayout,我已经创建了constraintLayout,但我使用的工具栏没有阴影高程。我看不到任何影子。以下是我到目前为止所拥有的图像: 我想把绿色部分抬高一点,加上一点阴影。您知道物料标题的方式。因此,当我滚动recyclerview时,它会在标题下显示它的Ogging。现在很标准 以下是我目前的代码: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayou
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/gl_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="76dp" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:elevation="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/gl_start"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary">
<ImageView
android:id="@+id/iv"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@android:drawable/btn_star"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/gl_start"
tools:itemCount="10"
tools:listitem="@layout/list_item" />
请注意,工具栏是粘性的,所以它不应该移动,但我只需要将其提升,我尝试在工具栏上用xml设置提升,但正如您所看到的,它并没有那么漂亮。如何放置阴影和高程 或者将您的
工具栏
包装在AppBarLayout
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
...>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
.../>
</com.google.android.material.appbar.AppBarLayout>
试试下面的例子-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="vertical">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/shadow"
android:titleTextAppearance="@color/White"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- your components -->
<View android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/toolbar_shadow"/>
</FrameLayout>
</LinearLayout>
@可绘制/工具栏阴影:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="@android:color/transparent"
android:endColor="#88333333"
android:angle="90"/>
</shape>
@颜色/阴影
<color name="shadow">#e74c3c</color>
#e74c3c
正是这样,谢谢,第一个选项起作用了。
<color name="shadow">#e74c3c</color>