2015-08-29 78 views
14
<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"> 

    <!--<include--> 
    <!--android:id="@+id/app_bar"--> 
    <!--layout="@layout/app_bar" />--> 


    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/rootLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/app_bar"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="256dp"> 

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

       <ImageView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:scaleType="centerCrop" 
        android:src="@drawable/header" 
        app:layout_collapseMode="parallax" 
        app:layout_collapseParallaxMultiplier="0.7" /> 

       <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbarTutorial" 
        android:layout_width="match_parent" 
        android:layout_height="50dp" 
        android:minHeight="?attr/actionBarSize" 
        app:layout_collapseMode="pin" 
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 

       <TextView 
        android:id="@+id/textViewAppBar" 
        android:layout_width="match_parent" 
        android:layout_height="50dp" 
        android:layout_gravity="bottom" 
        android:gravity="center" 
        android:scrollbarDefaultDelayBeforeFade="@id/toolbarTutorial" 
        android:text="test" 
        android:textColor="@color/white" 
        android:textSize="30sp" /> 


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

      <!--<android.support.design.widget.TabLayout--> 
      <!--android:id="@+id/tabLayout"--> 
      <!--android:layout_width="match_parent"--> 
      <!--android:layout_height="wrap_content"--> 
      <!--app:layout_scrollFlags="scroll|enterAlways"/>--> 

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


     <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/swipe_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v4.widget.NestedScrollView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fillViewport="true" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


       <!--<android.support.v4.widget.SwipeRefreshLayout--> 
       <!--android:id="@+id/activity_main_swipe_refresh_layout"--> 
       <!--android:layout_width="match_parent"--> 
       <!--android:layout_height="wrap_content">--> 
       <LinearLayout 
        android:id="@+id/linearLayoutWithData" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical" 
        app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

        <!--<TextView--> 
        <!--android:id="@+id/textViewInternet"--> 
        <!--android:layout_width="match_parent"--> 
        <!--android:layout_height="wrap_content"--> 
        <!--android:textColor="@color/black"/>--> 


       </LinearLayout> 
       <!--</android.support.v4.widget.SwipeRefreshLayout>--> 
      </android.support.v4.widget.NestedScrollView> 
     </android.support.v4.widget.SwipeRefreshLayout> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/btnFAB" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|right" 
      android:layout_marginBottom="@dimen/codelab_fab_margin_bottom" 
      android:layout_marginRight="@dimen/codelab_fab_margin_right" 
      android:src="@drawable/ic_plus_blue" 
      app:fabSize="normal"> 

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

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

我想要的數據linearlayout是在「textViewAppBar」之下。我試圖實現一個RelativeLayout但它不起作用。現在,數據顯示爲完整的佈局,但我希望在「textViewAppBar」下面有這個,但SwipeRefreshLayout應該是match_parent,有什麼建議嗎?感謝:-)SwipeRefreshLayout與NestedScrollView和LinearLayout

回答

4

我解決它通過自己把SwipeRefreshLayout爲主要佈局,並添加其餘兒童

+3

你能分享片段嗎?哪個主要佈局? –

+0

@RahulPatil看看我的回答下面 –

5

使用本

<android.support.v4.widget.SwipeRefreshLayout 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:id="@+id/swipeContainer" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.design.widget.CoordinatorLayout 
    ... your attribute here ... > 

    <android.support.design.widget.AppBarLayout 
     ... your attribute here ... > 

     <android.support.design.widget.CollapsingToolbarLayout 
      ... your attribute here ... > 

      ... your element here ... 

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

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

    <android.support.v4.widget.NestedScrollView 
     ... your attribute here ... > 

     ... your element here ... 

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

+0

與此可摺疊佈局不工作..意思是不collpasing – GvSharma

18

app:layout_behavior應該被添加到直接子CoordinatorLayout

所以你應該將app:layout_behavior="@string/appbar_scrolling_view_behavior"NestedScrollView移動到SwipeRefreshLayout

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

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

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <android.support.v4.widget.NestedScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fillViewport="true"> 
      ... 
     </android.support.v4.widget.NestedScrollView> 

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

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

app:應該將layout_behavior添加到CoordinatorLayout的直接子節點。並且需要在SwipeLayout中使用NestedScrollView之後;

<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/swipe_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 
     ... 
    </android.support.v4.widget.NestedScrollView> 

</android.support.v4.widget.SwipeRefreshLayout> 
相關問題