[英]Recycler view items are not scrolling?
我正在處理Recycler視圖,在這里我將三個回收站視圖水平放置在一個布局中。問題是第二個和第三個回收站視圖項目顯示但是無法滾動,即使使用嵌套滾動內部並因此附加xml.Kindly建議我如何滾動第二和第三個回收者視圖。
<RelativeLayout
android:id="@+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="@color/color_bottom_sheet"
android:elevation="@dimen/z_bottom_sheet"
app:behavior_hideable="true"
app:behavior_peekHeight="80dp"
app:layout_behavior="@string/string_bottom_sheet_behavior">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rightLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/lay1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewmonth"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true"
android:verticalScrollbarPosition="right">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/lay2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00ff00">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewdate"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/lay3"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000ff">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewyear"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/text_view_sheet_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_vertical_margin"
android:text="@string/text_pull_to_show_more"
android:textSize="@dimen/text_size_medium"
android:visibility="gone" />
<TextView
android:id="@+id/text_view_more_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text_view_sheet_title"
android:paddingLeft="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_vertical_margin"
android:text="@string/text_more_contet_to_user"
android:textSize="@dimen/text_size_big"
android:textStyle="bold"
android:visibility="gone" />
<Button
android:id="@+id/btnclick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/text_view_more_content"
android:layout_marginLeft="@dimen/activity_vertical_margin"
android:layout_marginRight="@dimen/activity_vertical_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:text="@string/text_click_me"
android:visibility="gone" />
</RelativeLayout>
// Java的
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerViewmonth);
RecyclerView recyclerdate = (RecyclerView) findViewById(R.id.recyclerViewdate);
RecyclerView recycleryear = (RecyclerView) findViewById(R.id.recyclerViewyear);
ButterKnife.bind(this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
LinearLayoutManager linearLayoutManagerdate = new LinearLayoutManager(getApplicationContext());
LinearLayoutManager linearLayoutManageryear = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(linearLayoutManager);
recyclerdate.setLayoutManager(linearLayoutManagerdate);
recycleryear.setLayoutManager(linearLayoutManageryear);
recyclerView.setNestedScrollingEnabled(false);
recyclerdate.setNestedScrollingEnabled(false);
recycleryear.setNestedScrollingEnabled(false);
for (int i = 0; i <= 31; i++) {
dayList.add(String.valueOf(i));
}
CustomAdapter customAdapter = new CustomAdapter(MainActivity.this, monthList);
recyclerView.setAdapter(customAdapter);
DayAdapter dayAdapter=new DayAdapter(MainActivity.this,dayList);
recyclerdate.setNestedScrollingEnabled(false);
recyclerdate.setAdapter(dayAdapter);
recyclerdate.setNestedScrollingEnabled(false);
YearAdapter yearAdapter=new YearAdapter(MainActivity.this,monthList);
recycleryear.setAdapter(yearAdapter);
在您初始化回收站視圖的位置發布您的Java代碼。 此外,嘗試從嵌套滾動視圖中刪除回收器視圖(您可以放置它們而不嵌套滾動視圖)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rightLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/lay1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewmonth"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/lay2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00ff00">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewdate"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/lay3"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#0000ff">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewyear"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
將所有Recycler視圖保留在嵌套滾動視圖中。
將父布局高度更改為match_parent。 喜歡
<RelativeLayout
android:id="@+id/layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_bottom_sheet"
android:elevation="@dimen/z_bottom_sheet"
app:behavior_hideable="true"
app:behavior_peekHeight="80dp"
app:layout_behavior="@string/string_bottom_sheet_behavior">
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.