2016-12-07 8 views
0

テキストの長さに応じて異なる列番号を持つミディアムアプリのようなグリッドビューを作成したいとします。異なる列番号を持つグリッドビューを作成する

標準GridLayoutManagerRecyclerViewと組み合わせて使用​​することは、あまり効果的ではないようです。

同じ効果を得るためのよりよい方法がありますか。できるだけRecyclerViewを使用してください。

Medium category selection

答えて

0

それは実際に可能です。ここでは、RecyclerViewの行が水平に中央に配置され、ボタンが動的に追加されるというトリックがあります。各ボタンの位置は気にしないでください。幅はwrap_contentに設定されていて、行は中央に配置されているので、自動的にこの結果がレンダリングされます。あなた次第ですが、2,3または4のアイテムを並べて配置するかどうかを決めなければなりません。文字の制限を定義できます。ボタンのパディングを考慮して、RecyclerViewに送信するデータソースを作成することができます。これは私がコードを見ることなくあなたに与えることができる一般的な概念です。

0

に役立つことがあります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<LinearLayout 
    android:id="@+id/row1" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


<android.support.v7.widget.RecyclerView 
    android:id="@+id/articles" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="horizontal" 
    android:scrollbarStyle="outsideInset" 
    android:layout_weight="1" 
    android:layout_gravity="center"/> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/articles2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="horizontal" 
    android:scrollbarStyle="outsideInset" 
    android:layout_weight="1" 
    android:layout_gravity="center"/> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/articles3" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="horizontal" 
    android:scrollbarStyle="outsideInset" 
    android:layout_weight="1"/> 
</LinearLayout> 
</RelativeLayout> 
:それは

レイアウトXMLコードを助けている場合、私に教えてください

関連する問題