Answer the question
In order to leave comments, you need to log in
How to lay out a grid in android studio?
I want to arrange the elements like this:
and it turns out like this: the
main_activity.xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".my"
android:background="@color/bg_color">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/date"
android:id="@+id/textViewDate"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/prevButton"
android:src="@android:drawable/ic_media_previous"
android:layout_toStartOf="@+id/textViewDate"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/textViewDate"
android:layout_marginRight="37dp"
android:layout_alignBottom="@+id/textViewDate"
android:clickable="false"
android:onClick="onClickPrev" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nextButton"
android:layout_toEndOf="@+id/textViewDate"
android:src="@android:drawable/ic_media_next"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textViewDate"
android:layout_marginLeft="40dp"
android:layout_alignBottom="@+id/textViewDate"
android:onClick="onClickNext" />
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/customGrid"
android:layout_below="@+id/prevButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:numColumns="auto_fit"
android:layout_toStartOf="@+id/prevButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/item_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="@+id/item_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
Answer the question
In order to leave comments, you need to log in
<GridView
a:id="@+id/gridView"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:columnWidth="90dp"
a:numColumns="auto_fit"
a:verticalSpacing="10dp"
a:horizontalSpacing="10dp"
a:stretchMode="columnWidth"
a:gravity="center">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question