【问题标题】:Activity's element covering ToolbarActivity 的元素覆盖 Toolbar
【发布时间】:2016-11-04 21:03:12
【问题描述】:

我的 XML:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:layout_gravity="center_horizontal|top"
    android:layout_marginTop="50dp"
    android:indeterminate="true"
    android:visibility="invisible"
    android:layout_centerHorizontal="true" />

    <android.support.v7.widget.Toolbar
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:id="@+id/toolbarTab2"
        app:theme="@style/ToolBarStyle"
        android:elevation="5dp"
        android:paddingTop="20dp"
        android:textAlignment="center"
        android:background="@android:color/holo_red_light">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="MY TOOLBAR TITLE"
            android:layout_gravity="center"
            android:id="@+id/toolbar_title"
            android:textSize="20sp"
            android:textStyle="bold"
            android:background="#00000000"
            android:textColor="#ffffff" />

    </android.support.v7.widget.Toolbar>


    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:foregroundGravity="left|right">




    <android.support.v7.widget.RecyclerView

        android:id="@+id/notesList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"

        >

    </android.support.v7.widget.RecyclerView>


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

</RelativeLayout>

由于Elevation,我的工具栏在 api 21 及更高版本上运行良好,但在 api

在这里你可以看到我的工具栏在cardview后面

【问题讨论】:

    标签: android android-layout android-toolbar android-elevation


    【解决方案1】:
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical">
    
    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_gravity="center_horizontal|top"
        android:layout_marginTop="50dp"
        android:indeterminate="true"
        android:visibility="invisible"
        android:layout_centerHorizontal="true" />
    
    <android.support.v7.widget.Toolbar
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:id="@+id/toolbarTab2"
        app:theme="@style/ToolBarStyle"
        android:elevation="5dp"
        android:paddingTop="20dp"
        android:textAlignment="center"
        android:background="@android:color/holo_red_light">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="MY TOOLBAR TITLE"
            android:layout_gravity="center"
            android:id="@+id/toolbar_title"
            android:textSize="20sp"
            android:textStyle="bold"
            android:background="#00000000"
            android:textColor="#ffffff" />
    
    </android.support.v7.widget.Toolbar>
    
    
    <android.support.v4.widget.SwipeRefreshLayout  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="?attr/actionBarSize" 
        android:clipToPadding="false"
        android:clipChildren="false"
        android:foregroundGravity="left|right">
    
    <android.support.v7.widget.RecyclerView
        android:id="@+id/notesList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
    
        >
    
    </android.support.v7.widget.RecyclerView>
    
    
    </android.support.v4.widget.SwipeRefreshLayout>
    
    </RelativeLayout>
    

    【讨论】:

    • 感谢您的回复,它可以工作,但我想覆盖内容,现在我的其他内容在工具栏下方,我想用我的工具栏覆盖其他内容,因为根据滚动显示可见和透明RecyclerView的
    • 你是说你想隐藏/显示你的工具栏相对于你的回收器视图的滚动?
    • 不,我已经这样做了,看到这个raw.githubusercontent.com/kanytu/android-parallax-recycleview/… 像这样
    • 我已经编辑了我的答案,看看是否对你有帮助,但我并不完全确定。但是,您可以使用支持库轻松完成您想要实现的目标。请参阅此链接以了解如何执行此操作guides.codepath.com/android/…
    • 好吧,你更新的答案与我想要的完全相反,现在我的布局和工具栏之间有一个额外的空间,我可以用 (- number) 添加这个填充吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-01
    • 2017-05-08
    • 2018-04-12
    相关资源
    最近更新 更多