Hello,
Welcome to our Microsoft Q&A platform!
In my example the ImageButton is inserted in the first row although I want to insert it in the second row.
There are things that need to be corrected.
- If you want to put an
ImageButton
in yourGridLayout
in the second row, theandroid:layout_row
should be1
,because the number ofrow
starts at0
.:
2.If you don't place any controls before placing an ImageButton, the previous row and column positions won't take up space. That's why it looks like it's in the first place.android:layout_row="1"
3.If you want to the ImageButton to look like in the second row, you can put a view in the first row, for example:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/GridLayout1"
android:columnCount="2"
android:layout_margin="10dp"
android:orientation="horizontal"
android:rowCount="4">
<View
android:visibility="visible"
android:layout_height="50dp"
android:layout_width="50dp"
android:textSize="14dip"
android:layout_row="0"
android:layout_column="0" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_row="1"
android:layout_column="0"
android:src="@drawable/image1" />
</GridLayout>
The result is:
For more details, you can check:https://learn.microsoft.com/en-us/xamarin/android/user-interface/layouts/grid-layout
Best Regards,
Jessie Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.