如何在recyclerview中使用键滚动?

时间:2018-04-19 02:37:33

标签: android android-recyclerview android-flexboxlayout

enter image description here

我有关于recyclerview的问题 在那张图片中蓝色是recyclerview 黄色现在是焦点imageview 当我使用keydown时,我想向下滚动,所以想要显示绿色imageview 但它没有走路

我怎么能解决它?

主要活动是

    recyclerAdapter = new RecyclerAdapter(this, this);
    recyclerView = findViewById(R.id.recyclerView);

    final FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
    layoutManager.setFlexWrap(FlexWrap.WRAP);
    layoutManager.setAlignItems(AlignItems.CENTER);

    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(recyclerAdapter);

布局

<android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>

和观看者

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnFocusChangeListener {
    FrameLayout frameLayout;
    ImageView image;

    public ViewHolder(View itemView) {
        super(itemView);
        frameLayout = itemView.findViewById(R.id.frameLayout);
        image = (ImageView) itemView.findViewById(R.id.imageView);
        FlexboxLayoutManager.LayoutParams layoutParams = (FlexboxLayoutManager.LayoutParams) itemView.getLayoutParams();
        layoutParams.setFlexGrow(1.0f);

    }

1 个答案:

答案 0 :(得分:0)

向imageView添加clicklistener并使用

layoutManager.scrollToPositionWithOffset(position);