這裏是我構建循環視圖如何在android中的horizontal recycleview中定義項目的數量?
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
ItemData itemsData[] = { new ItemData("Help",R.drawable.profile_pic),
new ItemData("Delete",R.drawable.profile_pic),
new ItemData("Cloud",R.drawable.profile_pic),
new ItemData("Favorite",R.drawable.profile_pic),
new ItemData("Like",R.drawable.profile_pic),
new ItemData("Rating",R.drawable.profile_pic)};
LinearLayoutManager l = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(l);
MyAdapter mAdapter = new MyAdapter(itemsData);
recyclerView.setAdapter(mAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());
它的工作原理,但問題是,它每次只顯示1項,如何更改爲2項?這意味着,該圖標應該是屏幕寬度和總的50%具有每頁
2個圖標這樣的(無需分頻器的):
icon1 | icon2
XML(主要活動)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context="com.hmkcode.android.recyclerview.MainActivity" >
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
/>
</RelativeLayout>
XML(項目)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp">
<!-- icon -->
<ImageView
android:id="@+id/item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/profile_pic" />
<!-- title -->
<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#000000"
android:textSize="22sp" />
</RelativeLayout>
感謝您的幫助
更新:
通知該應用程序只有potarit方向,以便可以忽略景觀的情況下
當前的結果:
而GridLayoutManager不是確切的行爲
GridLayoutManager g = new GridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false);
它是否可滾動?你能分享截圖嗎? –
是可滾動的。 – user3538235
更新了當前和期望的結果 – user3538235