gpt4 book ai didi

android - 如何使用 NestedScrollView 使工具栏透明 ImageView

转载 作者:行者123 更新时间:2023-11-29 23:28:05 24 4
gpt4 key购买 nike

我想制作一个透明的工具栏。我试过但还是失败了。我写了 XML。滚动时,图片会上移,toolbar会透明,箭头向后可以调用finish函数。

工具栏截图:

Toolbar

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:orientation="vertical"
tools:context=".DetailActivity">

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000"
app:theme="@style/CustomActionBar">

<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_arrow_back"
android:onClick="onback" />
</android.support.v7.widget.Toolbar>

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar_detail"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorSilver"
android:orientation="vertical">


</LinearLayout>


</android.support.v4.widget.NestedScrollView>


</RelativeLayout>

自定义工具栏:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Custom" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>

<style name="CustomActionBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
</resources>

最佳答案

使用坐标布局而不是相对布局

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#0000"
app:theme="@style/CustomActionBar">

<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_arrow_back"
android:onClick="onback" />
</android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>


<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar_detail"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorSilver"
android:orientation="vertical"></LinearLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>

关于android - 如何使用 NestedScrollView 使工具栏透明 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53160576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com