2017-06-14 63 views
0

我有一個屏幕包含可摺疊工具欄(AppBarLayout)和滾動內容與NestedScrollviews內容下推

我的主要佈局:

<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.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:theme="@style/ToolbarTheme" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/actionBarHeight" 
     android:background="@color/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

    <android.support.v4.widget.NestedScrollView 
     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:fillViewport="true" 
     android:scrollbars="none" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
    <FrameLayout 
     android:id="@+id/layoutMainContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    </android.support.v4.widget.NestedScrollView> 

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

而且我投入的FrameLayout layoutMainContent佈局含量如下

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
android:background="@color/colorBackground"> 

<LinearLayout 
    android:id="@+id/layoutAbout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_centerInParent="true"> 
    <ImageView 
     android:id="@+id/ivLogo" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center_horizontal" 
     android:src="@drawable/logo"/> 
</LinearLayout> 

<TextView 
    android:id="@+id/tvViewDetail" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:textColor="@color/colorPrimary" 
    android:text="@string/see_license" 
    android:gravity="center_horizontal"/> 
</RelativeLayout> 

我想要的是徽標圖像是在中心和TextView(tvViewDetail)是在屏幕的底部。但是,徽標圖像不在中間(稍微向下推),並且tvViewDetail被推出屏幕。

有什麼我做錯了嗎?任何建議都會有幫助! 謝謝大家,

回答

0

試試這種方式我希望它有幫助。

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/colorBackground"> 

     <LinearLayout 
       android:id="@+id/layoutAbout" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:gravity="center" 
       android:layout_centerInParent="true"> 
        <ImageView 
         android:id="@+id/ivLogo" 
         android:layout_width="100dp" 
         android:layout_height="100dp" 
         android:src="@drawable/logo"/> 

        <TextView 
         android:id="@+id/tvViewDetail" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textColor="@color/colorPrimary" 
         android:text="@string/see_license"/> 
       </LinearLayout> 


       </RelativeLayout> 

因此LinearLayout中的高度和寬度會WRAP_CONTENT和重力將中心,使線性佈局的所有子將在所述線性佈局的中心。線性佈局也出現在相對佈局的中心。