我在TabLayout中有一个片段xml。TabLayout位于CollapsingToolbar布局中,当滚动TabLayout中片段的内容时,该布局会折叠。我有一个片段,需要一个TextView在recyclerView上面。
如果我的布局如下所示,来自我以前问过的这个问题
<LinearLayout>
<NestedScrollView
<TextView>
</TextView>
</NestedScrollView>
<View>
</View>
<RecyclerView>
</RecyclerView>
</LinearLayout>它工作正常,直到TextView有如此多的内容以至于它填充或占用了大部分屏幕,RecyclerView才会使用视图中要显示的剩余空间:
因此,回收视图只留下极小的空间可观看。如果Textview占据了整个屏幕,recyclerView就不会显示。
如果布局为:
<FrameLayout>
<NestedScrollView
<TextView>
</TextView>
</NestedScrollView>
<View>
</View>
<RecyclerView>
</RecyclerView>
</FrameLayout>只有recyclerView显示,而TextView只是不存在。
如果布局是:
<NestedScrollView>
<LinearLayout
<TextView>
</TextView>
<View>
</View>
<RecyclerView>
</RecyclerView>
</LinearLayout>
</NestedScrollView>TextView只显示RecyclerView中是否有内容。
我怎样才能让TextView滚动到窗口外来显示回收视图,这样屏幕就可以从下面这样做了:
对此:
____________|
我当前的XML代码只显示RecyclerView,而不显示TextView:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/item_shipping_shipping_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|left"
android:padding="@dimen/margin_16"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.NestedScrollView>
<View
android:id="@+id/line43"
android:layout_width="match_parent"
android:layout_height="@dimen/line_height"
android:background="@color/light_gray"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/item_shipping_fragment_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</FrameLayout>发布于 2016-03-07 07:57:20
我唯一解决问题的方法是将列表以编程方式嵌套在嵌套的scrollView中。我无法同时使用RecyclerView和nestedScrollview。
发布于 2016-03-03 20:30:49
试着增加两个布局的权重。
例如,如果希望TextView部件小于或等于RecyclerView部件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/item_shipping_shipping_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|left"
android:padding="@dimen/margin_16"/>
</android.support.v4.widget.NestedScrollView>
<View
android:id="@+id/line43"
android:layout_width="match_parent"
android:layout_height="@dimen/line_height"
android:background="@color/light_gray"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/item_shipping_fragment_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>这样,包含布局的TextView就会知道,它一方面应该包装内容,另一方面应该具有与RecyclerView相同的权重,并且它会从中挑选最小的内容。
发布于 2016-02-24 12:12:23
与框架布局不同,采用垂直方向的线性布局,并将回收视图放在另一个线性布局中:
<LinearLayout orientation=verticle >
<LinearLayout
>
<android.support.v4.widget.NestedScrollView>
<TextView/>
</android.support.v4.widget.NestedScrollView>
<View
/>
</LinearLayout>
<LinearLayout>
<android.support.v7.widget.RecyclerView/>
</LinearLayout>
</LinearLayout>两个子布局的布局高度应设置为wrap_content
https://stackoverflow.com/questions/35599358
复制相似问题