マイRecyclerViewはMainActivityためCardViewRecyclerViewは(ない焦点に?)にスクロールしません後にクリックされた一回
XMLのリストが含まれていない限り:私は上記のRecyclerView用のアダプタを使用
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.RecyclerView
android:id="@+id/view_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
<FloatingActionButton/>
</android.support.design.widget.CoordinatorLayout>
をカードを入れるアダプタの内側ViewHolderを膨張させるために使用
のxml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout"
android:paddingTop="2dp"
android:paddingRight="2dp"
android:paddingLeft="2dp"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardBackgroundColor="@android:color/holo_red_light"
card_view:cardPreventCornerOverlap="true"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="3dp"
card_view:contentPadding="7dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:id="@+id/relat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="false"
android:padding="10dp">
<TextView/>
//...
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
カードがクリック可能にするために、私はthese内のすべてのソリューションを試してみました - two人気の記事を、私はいつもこの奇妙なバグがあります
一度RecyclerViewをクリックしない限り、最初にアプリを起動すると、カードのリストはスクロールしません。あたかもRecyclerViewに焦点が当てられていないかのようです。また
、私はすべてのクリックリスナーまたはCardViewのクリッカブルを作成し、XMLだけでフォーカス可能コードを維持するために同じような方法を取り除く場合:
android:focusable="true"
android:focusableInTouchMode="false"
、それはすぐにスクロールを行いますが、できるだけ早くクリック(リスナー)メカニズムを追加したり、ViewHolderに「android:clickable = "true"」を含めても、そのバグが再現されます。 お知らせください。ありがとう
私のための問題を解決していないだけで、これを変更します。 NestedScrollViewを削除すると、RecyclerView領域はスクロールできなくなります。 – DanSoren
@ DanSoren使用しているサポートライブラリのバージョンは? –
また、あなたは 'android:layout_height =" match_parent "'を使ってみることができますか? –