1

当我向上滚动图像并显示标题时,我使用了协调器布局。工具栏标题显示在底部

但一个问题是在它显示在底部的一些移动设备。

enter image description here

这里是我...................................的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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.donation.bhatt.donation.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/image_size" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/main.backdrop" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:src="@drawable/mainwindow" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/maintoolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="parallax" 
       android:layout_gravity="top" 
       android:gravity="top" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

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


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/background" 
     android:elevation="4dp" 
     android:padding="15dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 


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

删除appbarlayout和检查 –

回答

0

你可以试试这

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar_top" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:minHeight="?attr/actionBarSize" 
    app:layout_collapseMode="parallax" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" > 


<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:id="@+id/toolbar_title" /> 


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

立刻设置工具栏的标题这样

Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top); 
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title); 
mTitle.setText("title"); 
+0

它的工作原理感谢您的帮助:) – user6523976

+0

我的名声小于15, StackOverflow不允许我upvote。对不起,那:( – user6523976

0

您可能需要使用可expandedTitleGravity标志CollapsingToolbarLayout设置标题重心居中水平

+0

我尝试这一点,但仍然没有工作 – user6523976