[英]Recycler View with multiple rows and columns - AutoFit like Flow Layout [Android]
我正在構建一個像這樣的布局的挑戰:
我的第一個見解是使用帶有適配器的RecyclerView,該適配器可以處理每個項目並使其布局膨脹。
到目前為止,還不是那么好。
到目前為止我有這個布局:
我可以感覺到我幾乎就在那里,但是真的......我花了一個星期思考如何讓它變得更好,或者就像UI提出的那樣。
我的一些嘗試是
伙計們,我不是在這里尋找一些已經完成的代碼安靜或有人來完成我的工作。 實際上我正在尋找隧道盡頭的燈光。
您好,如果您不想使用recyclerview,還有另一個使用自定義庫的示例,其行為類似於List GitHubLibrary TagLayout
示例代碼 :
mFlowLayout.setAdapter(new TagAdapter<String>(mVals) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false); tv.setText(s); return tv; } });
使用以下代碼,您可以預先設置所需的選擇:
mAdapter.setSelectedList(1,3,5,7,8,9);
將顯示如下結果: -
使用包含名為Chips的組件的新Google材料設計庫可以輕松完成此操作。 因此您不必使用RecyclerView。
芯片代表小塊中的復雜實體,例如聯系人。 它是一個圓形按鈕,由標簽,可選芯片圖標和可選的關閉圖標組成。 如果可以檢查芯片,可以點擊或切換芯片。
如何使用組件:
1.導入庫
implementation 'com.google.android.material:material:1.1.0'
2.使用以下代碼
<com.google.android.material.chip.ChipGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Your items here -->
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 1"/>
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 2"/>
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item 3"/>
<!-- End -->
</com.google.android.material.chip.ChipGroup>
您可以在此處找到更多詳細信息: 材料組件
現在可能為時已晚,但您也可以使用谷歌的FlexBoxLayout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.