I am trying to build such a view:
Supposing that lines represents GridLayout
and I need to build views 1x1 2x2 3x3 4x4 and 5x5. Views can begin not only from first cell. I can't handle this behavior, or maybe there is some alternatives to GridLayout
. To set 1x1 img is simple enough:
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="0"/>
but how to set one image in 2 cells and begin not from the first one ?
how to set one image in 2 cells and begin not from the first one ?
You need to use the xml
attributes layout_rowSpan
and layout_columnSpan
. For an ImageView
occupying 2x2 cells:
<ImageView
android:id="@+id/imageView"
android:layout_columnSpan="2"
android:layout_rowSpan="2"
android:layout_column="3"
android:layout_row="0"
/>
For those using android.support.v7.widget.GridLayout
: remember to change android
to app
where "app" is your XML namespace:
xmlns:app="http://schemas.android.com/apk/res-auto"
Note that you can omit the attributes layout_width
and layout_height
because with GridLayout
they are not required (and will make no difference).
For further information see also the documentation or the article on http://android-developers.blogspot.de
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.