RecyclerView waterfall flow layout

The last is a layout style layout waterfall, in fact, and almost the same grid layout, grid layout is neatly, and the waterfall is long or short of that, there is a sense of dislocation and fall, sometimes too rules does not look good, a little misplaced even more beautiful.

?? Waterfall stream? RecyclerView Item file layout should pay attention to, and can not write a fixed height, otherwise no effects. For example, we have such a change:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardElevation="4dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">

<ImageView
android:id="@+id/img_recy_item_3_pic"
android:layout_width="match_parent"
android:layout_height="120dp"
android:scaleType="centerCrop" />

<TextView
Android: ID = "@ + ID / tv_recy_item_3_name"
Android: layout_width = "the wrap_content"
Android: layout_height = "the wrap_content"
Android: layout_below = "@ ID / img_recy_item_3_pic"
Android: layout_centerInParent = "to true"
Android: layout_marginTop = "8DP"
Android : textSize = "16SP" />

</ RelativeLayout>
</android.support.v7.widget.CardView>
?? Note that the above code, cardview height can not be fixed, and the following textview height can not be fixed value, must written wrap_content, the adapter will not need to change, to change the place is the data format as well? RecyclerView layout management style.

We add data to this change, the name has a long or short, in order to form a form a waterfall of varying lengths.

Private void addStaggeredData () {
the Map <String, Object> Map = null;
the Random Random = new new the Random ();
String [] STR = {
"waterfall \ n",
"waterfall \ n waterfall \ n",
"waterfall flow \ n waterfall \ n waterfall \ n ",
" waterfall \ n waterfall \ n waterfall \ n waterfall \ n ",
};

for (int I = 0; I <30; I ++) {
int n- random.nextInt = (pics.length);
Map new new = the HashMap <> (http://www.amjmh.com/v/BIBRGZ_558768/);
map.put ( "PIC", pics [n-]);
map.put ( "name", names [n-] + "\ n-" + STR [random.nextInt (str.length)]);
staggeredData.add (Map);
}
}
------------- --------

Guess you like

Origin www.cnblogs.com/hyhy904/p/11347016.html
Recommended