机器人:RecyclerView内的滚动型(或视差) [英] android: RecyclerView inside a ScrollView (or parallax)
问题描述
我是 2 cardviews 与内多个控件的片段。
下面第二cardview我有一个 recyclerview ,这个工程完美
的问题是,recyclerview启动屏幕的最底部,并滚动recylcerview很小
previously使用列表视图,这使我适合你的内容,从而使滚动在屏幕上一次,但recylclerview不能。
如何使我的时候滚动了recyclerview,控件上去像视差效果呢?
编辑:更清晰,想象2 cardviews的片段,这些占据了80%的屏幕,上面的这些,有100个项目列表的recyclerview,但滚动是如此的渺小......列表视图让我适应到内容和滚动整个屏幕上一次。
这是我的XML布局:
< XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / svScroll
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:fillViewport =真正的>
< RelativeLayout的
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
<包括
机器人:ID =@ + ID / cvCampos1
布局=@布局/ ctlcabeceralibreta/>
<包括
机器人:ID =@ + ID / cvCampos2
布局=@布局/ ctlcabeceralibreta2/>
< android.support.v7.widget.RecyclerView
机器人:ID =@ + ID / rvRegistros
机器人:layout_width =FILL_PARENT
机器人:layout_height =1000dp
机器人:layout_below =@ ID / cvCampos2
机器人:滚动条=垂直/>
< / RelativeLayout的>
< /滚动型>
这是screenshoot:
把一个固定的高度工作!!!但我需要计算的高度 项的列表中的数
这适用于列表视图(我不与recyclerview测试吧)
公共静态无效setListViewHeightBasedOnChildren(ListView控件的ListView){
ListAdapter listAdapter = listView.getAdapter();
如果(listAdapter == NULL){
// pre-条件
返回;
}
INT totalHeight = listView.getPaddingTop()+ listView.getPaddingBottom();
的for(int i = 0; I< listAdapter.getCount();我++){
查看的listItem = listAdapter.getView(I,空,ListView控件);
如果(的listItem的instanceof的ViewGroup){
listItem.setLayoutParams(新ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
}
listItem.measure(0,0);
totalHeight + = listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams PARAMS = listView.getLayoutParams();
params.height = totalHeight +(listView.getDividerHeight()*(listAdapter.getCount() - 1));
listView.setLayoutParams(PARAMS);
}
编辑:
I have a fragment with 2 cardviews with multiple controls within.
below the second cardview I have a recyclerview, this works perfect.
the problem is that the recyclerview starts very bottom of the screen, and scroll the recylcerview is very small.
previously used a listview, and this kept me fit your content and thus make scroll across the screen at once, but with recylclerview can not.
How to make when I scroll in the recyclerview, controls go up like parallax effect?
EDIT: more clear, imagine 2 cardviews in a fragment, these occupy 80% of the screen, above of these, a recyclerview with a list of 100 items, but the scroll is so tiny...the listview let me adapt to the "content" and scroll the entire screen at once.
this is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/svScroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include
android:id="@+id/cvCampos1"
layout="@layout/ctlcabeceralibreta" />
<include
android:id="@+id/cvCampos2"
layout="@layout/ctlcabeceralibreta2" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvRegistros"
android:layout_width="fill_parent"
android:layout_height="1000dp"
android:layout_below="@id/cvCampos2"
android:scrollbars="vertical" />
</RelativeLayout>
</ScrollView>
this is the screenshoot:
putting a fixed height works !!! but I need to calculate the height of the number of items in the list
this works for listviews (i dont tested it with recyclerview)
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
if (listItem instanceof ViewGroup) {
listItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
Edit:
这篇关于机器人:RecyclerView内的滚动型(或视差)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!