2016-04-22 67 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滚动视图后,它不能滚动水平。 (在此之前它的水平滚动) –