2016-04-22 103 views
-2

裏面我有一個XML文件喜歡 -設置在頂部的LinearLayout,同時滾動這是滾動型

<ScrollView> 
    <LinearLayout> 
     <RelativeLayout> 
      <ImageView /> 
      <----more components---> 
     </RelativeLayout> 
     <LinearLayout 
      android:id="@+id/llSomeLayout"> 
      <----components---> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 

我想什麼是 - >當的LinearLayout ID爲@ + ID/llSomeLayout從上面到達頂部,希望阻止佈局從視圖中移出,或者希望在視圖之外顯示類似的視圖/佈局。 我應該遵循什麼機制來實現?

+0

我得到了答案,但我可以來了解請爲什麼我下投票? – Exigente05

回答

1

使用https://github.com/emilsjolander/StickyScrollViewItems

dependencies { 
    compile 'se.emilsjolander:StickyScrollViewItems:x.x.x' 
} 

然後

<StickyScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/sticky_scroll" 
android:layout_height="match_parent" android:layout_width="match_parent"> 

<LinearLayout 
    android:layout_height="match_parent" android:layout_width="match_parent" 
    android:orientation="horizontal"> 

    <!-- other children --> 

    <LinearLayout 
     android:id="@+id/llSomeLayout" 
     android:layout_height="300dp" 
     android:layout_width="match_parent" 
     android:tag="sticky"/> 

    <!-- other children --> 

</LinearLayout> 

+0

如何讓粘滯視圖變爲橫向滾動?在添加te sticky滾動視圖後,它不能滾動水平。 (在此之前它的水平滾動) –