2017-08-09 100 views

回答

1

讓你工具欄這樣

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    app:popupTheme="@style/AppTheme.PopupOverlay"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_error" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Did you know" 
      android:textColor="@android:color/white" /> 

     <TextView 
      android:id="@+id/FactTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="demo text" /> 

     <--> add here more controls<--> 

    </LinearLayout> 

</Toolbar> 
+0

謝謝你這就是我想要的! –

+1

@TomFinet如果這對你有幫助,請接受我的答案 –

-1

您可以使用以下方法:

  1. Collapsible Toolbar
  2. Coordinator Layout

一些真實的例子: https://antonioleiva.com/collapsing-toolbar-layout/ http://tutorialsbuzz.com/2015/11/android-collapsingtoolbarlayout-example_7.html

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

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

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

      <com.antonioleiva.materializeyourapp.SquareImageView 
       android:id="@+id/image" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scaleType="centerCrop" 
       android:fitsSystemWindows="true" 
       app:layout_collapseMode="parallax"/> 

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

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

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

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

儘管此鏈接可能會回答問題,但最好在此處包含答案的基本部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 –

+0

@NileshRathod - 我已經完成了所需的更改,請求您刪除投票。 –

+0

我沒有投票我只是建議你不要給鏈接在ans –