Android alignparentbottom用于在scrollview内部创建relativelayout
我试图在屏幕底部放置一些内容(在本例中为id为'bottomcontent'的LL),当用户开始滚动时,我希望在底部显示更多内容。有什么办法吗?我有以下代码,但没有滚动,因为下面的LL'bottomcontent'的高度为0Android alignparentbottom用于在scrollview内部创建relativelayout,android,scrollview,Android,Scrollview,我试图在屏幕底部放置一些内容(在本例中为id为'bottomcontent'的LL),当用户开始滚动时,我希望在底部显示更多内容。有什么办法吗?我有以下代码,但没有滚动,因为下面的LL'bottomcontent'的高度为0 Here is the code: <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" tools:c
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>
以下是代码:
我从你的问题中得到的是,你想要一个滚动视图,但你总是想在屏幕底部显示一个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>
android:layout\u alignParentBottom=“true”
这将使LL停滞在底部,其余部分将滚动。感谢您的回答,但事实并非如此。没有停滞的部分。只有当用户向上滚动时,才会显示LL。LL位于屏幕下方,在滚动时可用。它是否位于ScrollView的末尾,并且仅在用户向上滚动时显示?LL是ScrollView的一部分,但它是ScrollView的最后一个视图。如果这就是您所说的scrollview结束的意思,那么是的。因此,您在scrollview内的RL中有
android:layout\u height=“match\u parent”
。如果将内容包装到它会发生什么?因为你的RL占据了所有的高度,当然它会隐藏LL。所以,要么对两个layouts使用权重,要么对这两个layouts都包装内容……你解决问题了吗?我也有同样的,但我做不到: