我找不到任何使用最好的例子RecyclerView有StaggeredGridLayoutManager.甚至在Android Docs中也没有.
Q1.我需要一些例子,可以给有关如何使用适当的解释
RecyclerView有StaggeredGridLayoutManager.Q2.任何人都可以告诉我是否可以使用
RecyclerViewwith 创建以下布局StaggeredGridLayoutManager

到目前为止,我发现这个链接根本没用.
我还发现了cardlib的这个链接,但它在实现上太复杂了,而且依赖性太大会不必要地增加我的应用程序大小.
我已经创建了一个库,显示了RecyclerView的快速滚动条(这里,如果有人想要),我想决定何时显示以及何时隐藏快速滚动条.
我认为一个好的决定是,如果屏幕上没有显示的项目(或者有很多项目没有出现),在RecyclerView完成布局过程后,我会将快速滚动条设置为可见,如果所有项目都已显示,则无需显示.
我找不到RecyclerView的监听器/回调,告诉我它何时完成显示项目,以便我可以检查显示的项目数与项目数量相比.
在键盘出现时,recyclerView也可能会改变其大小并隐藏自己.
滚动侦听器可能没有帮助,因为它"一直"发生,我只需要检查RecyclerView何时更改其大小或项目计数(或数据)已更改.
我可以换用通知我的大小的变化,就像一个布局RecyclerView 这一个,我做了,但我不认为它会工作作为RecyclerView大概不会准备好,告诉多少项目都可见.
检查显示的项目数量的方法可以这样使用:
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(layoutManager);
...
Log.d("AppLog", "visible items count:" + (layoutManager.findLastVisibleItemPosition() -layoutManager.findFirstVisibleItemPosition()+1));
Run Code Online (Sandbox Code Playgroud)
如何在recyclerView显示其子视图时收到通知,以便我可以根据当前显示的内容来决定显示/隐藏快速滚动条?
我有一个非常简单的RecyclerView.这就是我设置分隔符的方法
DividerItemDecoration itemDecorator = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
itemDecorator.setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.news_divider));
recyclerView.addItemDecoration(itemDecorator);
Run Code Online (Sandbox Code Playgroud)
这是drawable/news_divider.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/white_two"/>
<size android:height="1dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
问题是由于某些愚蠢的原因,分隔符不仅仅是在项目之间创建的.但也是在最后一项之后.而且我只想在每个项目之后的项目之间.
知道如何防止分隔符在最后一项之后显示吗?
干杯谢谢
更新到v23.2.0之后,我的RecyclerView项目之间有巨大的空白垂直空间.
我的项目布局非常简单:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
Run Code Online (Sandbox Code Playgroud) 如何在循环视图示例中仅更改所选视图的背景颜色?只需更改单击项目视图的背景颜色.一次只能显示一个选定项目,背景颜色会发生变化,其余项目必须与选择前一样.这是我的代码:
主要活动
public class MainActivity extends AppCompatActivity {
RecyclerView rv1;
private final String android_versions[]={
"Donut",
"Eclair",
"Froyo",
"Gingerbread",
"Honeycomb",
"Ice Cream Sandwich",
"Jelly Bean",
"KitKat",
"Lollipop",
"Marshmallow"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void initViews(){
rv1=(RecyclerView)findViewById(R.id.recyclerView1);
rv1.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager=new LinearLayoutManager(getApplicationContext());
rv1.setLayoutManager(layoutManager);
RecyclerDataAdapter rda=new RecyclerDataAdapter(rv1,getApplicationContext(),android_versions);
rv1.setAdapter(rda);
}
}
Run Code Online (Sandbox Code Playgroud)
RecyclerDataadapter
public class RecyclerDataAdapter extends RecyclerView.Adapter<RecyclerDataAdapter.ViewHolder> {
private String android_versionnames[];
private Context context1;
private RecyclerView mRecyclerView;
public RecyclerDataAdapter(RecyclerView recylcerView,Context context,String android_versionnames[]){
this.android_versionnames=android_versionnames;
this.context1=context;
mRecyclerView=recylcerView;
setHasStableIds(true);
System.out.println("Inside dataadapter,Android …Run Code Online (Sandbox Code Playgroud) 我有一个RecyclerView扩展以下网格项:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/children_tile_border"
android:layout_marginTop="@dimen/children_tile_border"
android:clickable="true"
android:focusable="true"
android:background="?selectableItemBackground"
tools:ignore="RtlHardcoded">
<com.example.app.ui.widget.SquareImageView
android:id="@+id/child_picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_alignParentBottom="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="@color/tile_text_background"
android:gravity="center_vertical"
android:layout_alignParentBottom="true">
..............
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但除非我将SquareImageView's可见性设置为不可见,否则不会出现涟漪效应.似乎涟漪效应低于SquareImageView.我怎么能把它画成SquareImageView?
我需要在具有标题的组中对RecyclerView中的元素进行划分(如下图中的收件箱应用程序),请帮助我找出哪种方法对我的情况更好:1)我可以使用异构布局但它是在组中插入新元素不太方便(因为我需要检查是否已经添加了同一组的元素,或者我需要添加新的分隔符).因此,在这种情况下,我将所有具有此类数据结构的操作包装到一个单独的类中.
2)从理论上讲,我可以用自己的RecyclerView包装每个组,这是一个好主意吗?
当我将RecyclerView放在嵌套的scrollview中时,屏幕总是跳到RecyclerView的顶部而不是页面的顶部.这是一个简单的例子.
layout xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="@android:color/holo_blue_dark"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</layout>
Run Code Online (Sandbox Code Playgroud)
虚拟适配器的活动:
public class RecycleViewTestActivity extends AppCompatActivity {
public static class ExampleAdapter extends RecyclerView.Adapter<ExampleViewHolder> {
private Context context;
public ExampleAdapter(Context context) {
this.context = context;
}
@Override
public ExampleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
TextView view = new TextView(context);
view.setText("Test");
return new ExampleViewHolder(view);
}
@Override
public void onBindViewHolder(ExampleViewHolder holder, int position) {
} …Run Code Online (Sandbox Code Playgroud) 我有一组照片,我用它RecyclerView来显示它们.我希望在我的RecyclerViewspan 2列和2行中有第一个元素:

我知道我可以跨越2列setSpanSizeLookup:
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (position == 0) {
return 2;
} else {
return 1;
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是我怎么能让第一个项目跨越2行呢?
我尝试将第一个项目的高度设置为不同,通过膨胀不同的布局,其他布局的高度是其他布局的两倍,但这导致与第一个项目在同一行上的每个项目也被拉伸到该高度:
@Override
public ProfilePicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView;
if (viewType == TYPE_MAIN_PHOTO) {
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_main_profile_photo, parent, false);
} else {
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_profile_photo, parent, false);
}
return new ProfilePicViewHolder(itemView);
}
Run Code Online (Sandbox Code Playgroud)