2014-09-22 98 views
3

我试图把一些内容(在这种情况下,与ID'底部内容的LL')在屏幕的底部和当用户开始滚动我喜欢在底部显示更多的内容它。任何想法如何做到这一点?我有下面的代码,但没有滚动,因为下面的“bottomcontent”的LL得到高度= 0alignparentbottom为scrollview内的relativelayout

Here is the code: 
<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MyActivity" 
     android:background="@android:color/transparent" 
     android:fillViewport="true" 
     android:layout_alignParentTop="true"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <!-- I expect this to occupy one full screen, since its child is asking for align parent bottom = true--> 
      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@android:color/transparent" 
       android:id="@+id/top"> 
       <LinearLayout 
        android:id="@+id/bottomcontent" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/holo_green_dark" 
        android:layout_alignParentBottom="true" 
        > 

        <TextView 
         android:text="@string/hello_world" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:background="@android:color/holo_red_light" 
         /> 
       </LinearLayout> 
      </RelativeLayout> 
      <!-- When user scrolls, I expect this linear layout to be seen. But I get its height to be zero, so no scrolling--> 
      <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" 
       > 


       <TextView 
        android:text="hello_world hello_world hello_world hello_world hello_world hello_world hello_world " 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:background="@android:color/holo_blue_dark" 
        /> 
      </LinearLayout> 

     </LinearLayout> 
    </ScrollView> 

回答

3

我从你的问题得到的是你想要一个滚动视图,但你aloways希望LL显示在屏幕底部。即使用户滚动,LL应该显示在底部,对吗?你可以尝试下面的布局。

<RelativeLayout> 
    <ScrollView> 
     <RelativeLayout> 
      <!--...everything you want to show in scrollview --> 
     </RelativeLayout> 
    </ScrollView> 

    <LinearLayout 
     <!--...your layout which you want to always show at bottom.--> 
     android:layout_alignParentBottom="true"> 
    </LinearLayout> 

</RelativeLayout> 

这将使LL停滞在底部,其余部分将滚动。

+0

感谢您的回答,但那不完全是。没有停滞的部分。只有当用户向上滚动时才应该显示LL。 LL在屏幕下方并且在滚动时可用 – user3030130 2014-09-22 20:27:19

+0

那么它是否在ScrollView的末尾,并且仅在滚动时才显示给用户? – 2014-09-22 20:43:50

+0

LL是scrollview的一部分,但是它的最后一个视图。如果这就是你在scrollview结尾的意思,那么是的。 – user3030130 2014-09-22 20:52:32