[英]Recycler view inside Horizontal scroll view not work in android oreo but is working perfectly in below versions
下面的代碼不適用於oreo版本的android,但工作是其他版本。 我試圖使用水平滾動視圖在這種情況下,用戶必須能夠評論,其他評論顯示在Recycler view的幫助下。所以我在這段代碼中只有新版本的android有問題。所有人都建議我關於這個問題的想法。 這是代碼
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<FrameLayout
android:layout_width="200dp"
android:layout_height="175dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:background="@layout/button_background"
android:layout_marginTop="15dp"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/userfbpic1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="15dp"
android:src="@drawable/bg"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/current_username"
android:text="@string/current_username_forcomment"
android:layout_marginTop="12dp"
android:layout_marginStart="50dp"
android:textStyle="bold"
android:textColor="@color/background"
android:textSize="15sp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="60dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/background"
android:id="@+id/comments"
android:textSize="15sp"
android:hint="comment here"
android:imeOptions="actionDone"
android:singleLine="true"
android:textStyle="bold"
android:background="@android:color/transparent"
/>
</LinearLayout>
</FrameLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_comments"
android:layout_width="wrap_content"
android:nestedScrollingEnabled="false"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</HorizontalScrollView>
當您將RecyclerView
放置在相同方向的ScrollView
中時, RecyclerView
將擴展,膨脹並將其所有子項放入ScrollView
內, 從而無法解壓縮 。 當您拖動視圖時, RecyclerView
會消耗觸摸事件,而ScrollView
將不會滾動,除非您禁用RecyclerView
觸摸..
在recyclerview上的觸摸監聽器中添加以下代碼
recyclerview.addOnItemTouchListener (new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { int action = e.getAction(); switch (action) { case MotionEvent.ACTION_MOVE: rv.getParent().requestDisallowInterceptTouchEvent(true); break; } return false; } });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.