I made a mini game with images. I want to use the grid layout margin as board to keep dynamic the size. Now i have a problem with the pictures when I appear them they appear in full size and not in the grid cell.
Here is my activity main xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.codes.logicgarden.MainActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="false"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<ImageView
android:id="#+id/im00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_rowWeight="1"
android:adjustViewBounds="true"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="0" />
<ImageView
android:id="#+id/im01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:adjustViewBounds="true"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="1" />
<ImageView
android:id="#+id/im02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:adjustViewBounds="true"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="2" />
<ImageView
android:id="#+id/im03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="3" />
<ImageView
android:id="#+id/im04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="4" />
<ImageView
android:id="#+id/im10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="5" />
<ImageView
android:id="#+id/im11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="6" />
<ImageView
android:id="#+id/im12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="7" />
<ImageView
android:id="#+id/im13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="8" />
<ImageView
android:id="#+id/im14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="9" />
<ImageView
android:id="#+id/im20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="10" />
<ImageView
android:id="#+id/im21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="11" />
<ImageView
android:id="#+id/im22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="12" />
<ImageView
android:id="#+id/im23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="13" />
<ImageView
android:id="#+id/im24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_columnWeight="1"
android:layout_row="2"
android:layout_rowWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="14" />
<ImageView
android:id="#+id/im30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="15" />
<ImageView
android:id="#+id/im31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="16" />
<ImageView
android:id="#+id/im32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="17" />
<ImageView
android:id="#+id/im33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="18" />
<ImageView
android:id="#+id/im34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="19" />
<ImageView
android:id="#+id/im40"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="4"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="20" />
<ImageView
android:id="#+id/im41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="4"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="21" />
<ImageView
android:id="#+id/im42"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="4"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="22" />
<ImageView
android:id="#+id/im43"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="4"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="23" />
<ImageView
android:id="#+id/im44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_row="4"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="24" />
<ImageView
android:id="#+id/im50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="5"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="25" />
<ImageView
android:id="#+id/im51"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="5"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="26" />
<ImageView
android:id="#+id/im52"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="5"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="27" />
<ImageView
android:id="#+id/im53"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="5"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="28" />
<ImageView
android:id="#+id/im54"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_row="5"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="29" />
<ImageView
android:id="#+id/im60"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="6"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="30" />
<ImageView
android:id="#+id/im61"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="6"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="31" />
<ImageView
android:id="#+id/im62"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="6"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="32" />
<ImageView
android:id="#+id/im63"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_row="6"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="33" />
<ImageView
android:id="#+id/im64"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_row="6"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:background="#android:color/background_light"
android:onClick="dropIn"
android:tag="34" />
</GridLayout>
<RelativeLayout
android:id="#+id/playAgainLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/gridLayout"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="100dp"
android:background="#android:color/holo_green_dark"
android:visibility="invisible">
<TextView
android:id="#+id/winnerMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="204dp"
android:onClick="playAgain"
android:text="Play Again" />
</RelativeLayout>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
How can i make when i click on the images they will appear in the grid view cell where they are assigned like in the editor and not original size?
The program working when the images have fix size but i want to make it dynamic to all platform.
How should look
How appear in emulator
You should really use a gridView with a custom adapter. than you set the adapter with a click listener and thats it.
Because if you want to change something in the image you will only need to do it once and not 32 times.
here is a really nice tutorial that can get you started with https://www.raywenderlich.com/127544/android-gridview-getting-started
Related
I've designed a basic calculator in android.
As i designed it, i tested it on Emulator Pixel XL Device (API 28, Screen Resolution 1440x2560 560dpi) and worked fine.
"Emulator Layout"
But when I installed the app in Huawei Honor 4C (Android 6.0) It look hilarious.
"Huawei Honor 4c"
minimumSdkVersion: 21
targetSdkVersion: 28
My Design Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffeeeeee"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff">
<TextView
android:id="#+id/display"
android:layout_width="match_parent"
android:layout_height="100dp"
android:ems="10"
android:textSize="30sp"
android:gravity="end|bottom"
/>
</LinearLayout>
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:columnCount="4"
android:rowCount="5">
<Button
android:id="#+id/btnClear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:text="C" />
<Button
android:id="#+id/btnDivid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:text="/" />
<Button
android:id="#+id/btnMultiplication"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:text="X" />
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_column="3"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:text="Delete" />
<Button
android:id="#+id/btn7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="7"
android:text="7" />
<Button
android:id="#+id/btn8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="8"
android:text="8" />
<Button
android:id="#+id/btn9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="9"
android:text="9" />
<Button
android:id="#+id/btnMinus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_column="3"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:text="-" />
<Button
android:id="#+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="4"
android:text="4" />
<Button
android:id="#+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="5"
android:text="5" />
<Button
android:id="#+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="6"
android:text="6" />
<Button
android:id="#+id/btnPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="2"
android:layout_rowWeight="1"
android:layout_column="3"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:text="+" />
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="1"
android:text="1" />
<Button
android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="2"
android:text="2" />
<Button
android:id="#+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_rowWeight="1"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="3"
android:text="3" />
<Button
android:id="#+id/btnEqual"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="3"
android:layout_rowSpan="2"
android:layout_rowWeight="1"
android:layout_column="3"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:background="#color/colorPrimaryDark"
android:onClick="numberClicked"
android:text="=" />
<Button
android:id="#+id/btn0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_rowWeight="1"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="0"
android:text="0" />
<Button
android:id="#+id/btnDot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="4"
android:layout_rowWeight="1"
android:layout_column="2"
android:layout_columnWeight="2"
android:layout_gravity="fill"
android:onClick="numberClicked"
android:tag="."
android:text="." />
</GridLayout>
</LinearLayout>
What are the possible reasons?
I think that this apparent problem is related to the attribute android:supportsRtl="true" and the different API levels of your device/emualtor.
Add in manifest in application tag
<application
android:name=".Application"
android:supportsRtl="true">
If set to true and targetSdkVersion is set to 17 or higher else false
Uninstall app in device and clear project then install to real device again.
If it works give me a thumbs up ..Keep coding :)
I am trying to make an app which contains a grid layout. I have to insert 4 buttons in the layout but I am facing problems regarding the alignment of these buttons.
Here is a screenshot and the xml file:
XML file:
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/sumTextView"
android:columnCount="2"
android:rowCount="2">
<Button
android:id="#+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="0"
android:layout_gravity="fill"
android:layout_row="0"
android:layout_rowWeight="0"
android:onClick="chooseAnswer"
android:tag="0"
android:text="3"
android:textSize="80sp" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="0"
android:layout_gravity="fill"
android:layout_row="0"
android:layout_rowWeight="0"
android:onClick="chooseAnswer"
android:tag="1"
android:text="3"
android:textSize="80sp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnWeight="0"
android:layout_gravity="fill"
android:layout_row="1"
android:layout_rowWeight="0"
android:onClick="chooseAnswer"
android:tag="2"
android:text="3"
android:textSize="80sp" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="0"
android:layout_gravity="fill"
android:layout_row="1"
android:layout_rowWeight="0"
android:onClick="chooseAnswer"
android:tag="3"
android:text="3"
android:textSize="80sp" />
</GridLayout>
Can someone tell me what the error is?
Add android:layout_columnWeight="1" and android:layout_rowWeight="1" to all cells.
Like this:
<GridLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/sumTextView"
android:columnCount="2"
android:rowCount="2"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="#+id/button0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:onClick="chooseAnswer"
android:tag="0"
android:text="3"
android:textSize="80sp" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_row="0"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:onClick="chooseAnswer"
android:tag="1"
android:text="3"
android:textSize="80sp" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:onClick="chooseAnswer"
android:tag="2"
android:text="3"
android:textSize="80sp" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_row="1"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:onClick="chooseAnswer"
android:tag="3"
android:text="3"
android:textSize="80sp" />
</GridLayout>
I am trying to make a calculator app and i used grid for the buttons but when i do that by default there are some margins around the buttons even though i didn't specify one.
yellow part is the grid layout.
Now i tried this method given here. This doesn't seem to work, anyone?
P.s: i am new to android.
Code
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:columnCount="3"
android:rowCount="5"
android:layout_weight="1"
android:useDefaultMargins="false"
android:alignmentMode="alignMargins"
android:rowOrderPreserved="false"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_rowWeight="1"
android:text="Button"
tools:layout_editor_absoluteX="136dp"
tools:layout_editor_absoluteY="100dp" />
<Button
android:id="#+id/button5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_rowWeight="1"
android:text="Button"
tools:layout_editor_absoluteX="116dp"
tools:layout_editor_absoluteY="289dp" />
<Button
android:id="#+id/button6"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_row="0"
android:layout_rowWeight="1"
android:text="Button"
tools:layout_editor_absoluteX="129dp"
tools:layout_editor_absoluteY="255dp" />
<Button
android:id="#+id/button8"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="1"
android:layout_rowWeight="1"
android:text="Button"
tools:layout_editor_absoluteX="64dp"
tools:layout_editor_absoluteY="259dp" />
<Button
android:id="#+id/button9"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="1"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button10"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_row="1"
android:layout_rowWeight="1"
android:text="Button"
tools:layout_editor_absoluteX="129dp"
tools:layout_editor_absoluteY="217dp" />
<Button
android:id="#+id/button12"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="2"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button13"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="2"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button14"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_row="2"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button16"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="3"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button17"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="3"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button18"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_row="3"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button20"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="0"
android:layout_columnWeight="1"
android:layout_row="4"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button21"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_row="4"
android:layout_rowWeight="1"
android:text="Button" />
<Button
android:id="#+id/button22"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_row="4"
android:layout_rowWeight="1"
android:text="Button" />
</GridLayout>
I am building the layout of my App. It uses the default Tabs layout and the fragment is a Relative Layout with a GridLayout and a TableLayout in it.
At the bottom of the Screen I have a View, which should be fixed to the bottom of the screen with android:layout_alignParentBottom="true" and the Preview shows the layout I intend.
When I run the App in the Simulator the Android On Screen Buttons overlap and cover the lower Part of my App.
Preview:
Simulator:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp" >
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#android:color/white"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_above="#+id/bottomView"
android:id="#+id/spacer"/>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:columnCount="3"
android:rowCount="2"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
android:background="#android:color/white"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:id="#+id/bottomView"
>
<TextView
android:text="Punkte ø"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:textSize="18sp" />
<TextView
android:text="15.0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:textSize="24sp" />
N<TextView
android:text="Noten ø"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:textSize="18sp" />
<TextView
android:text="1.0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:textSize="24sp" />
<TextView
android:text="Anzahl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:textSize="18sp" />
<TextView
android:text="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:textSize="24sp" />
</GridLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_red_dark"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView"
android:layout_above="#id/spacer"
android:id="#+id/red"
>
<GridLayout
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3"
android:layout_below="#+id/textView"
android:layout_above="#id/spacer"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="14"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AC"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DEL"
android:layout_gravity="fill"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:textColor="#android:color/white"
/>
</GridLayout>
</TableLayout>
<TextView
android:text="15 15 15 15 15"
android:layout_width="wrap_content"
android:layout_height="65dp"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textAlignment="center"
android:gravity="center"
android:background="#android:color/darker_gray" />
How can I make the white bottom view stick to the botttom without being overlaped by the naviugation buttons?
Please replace with this code you can see perfect layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="65dp"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#android:color/darker_gray"
android:gravity="center"
android:text="15 15 15 15 15"
android:textAlignment="center"
android:textAppearance="#style/TextAppearance.AppCompat.Display1" />
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottomView"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#android:color/white"
android:columnCount="3"
android:fitsSystemWindows="true"
android:horizontalSpacing="0dp"
android:orientation="vertical"
android:rowCount="2"
android:verticalSpacing="0dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:text="Punkte ø"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:text="15.0"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:text="Noten ø"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:text="1.0"
android:textSize="24sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:text="Anzahl"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:text="5"
android:textSize="24sp" />
</GridLayout>
<View
android:id="#+id/spacer"
android:layout_width="fill_parent"
android:layout_height="4dp"
android:layout_above="#id/bottomView"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#android:color/white" />
<TableLayout
android:id="#+id/red"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#id/textView"
android:layout_above="#id/spacer"
android:background="#android:color/holo_red_dark">
<GridLayout
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/spacer"
android:layout_below="#id/textView"
android:columnCount="3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="13"
android:textColor="#android:color/white" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="14"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="15"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="10"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="11"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="12"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="7"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="8"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="9"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="4"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="5"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="6"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="1"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="2"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="3"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="AC"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="0"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:background="#color/colorAccent"
android:text="DEL"
android:textColor="#android:color/white"
/>
</GridLayout>
</TableLayout>
I'm currently taking an Android Development course in Udemy, and I'm currently learning how to build a basic phrases app, which consists of a Grid Layout. I followed exactly what the instructor did with the XML part, and I got an error that the instructor didn't get:
This GridLayout layout or its RelativeLayout parent is useless. A layout with children that has no siblings, is not a scrollview or a root layout, and does not have a background, can be removed and have its children moved directly into the parent for a flatter and more efficient layout hierarchy.
This is the XML:
<?xml version="1.0" encoding="utf-8"?>
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.jumin.basicphrases.MainActivity">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Hello"
android:onClick="buttonTapped"
android:id="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="How are you?"
android:onClick="buttonTapped"
android:id="#+id/howareyou" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Good Evening"
android:onClick="buttonTapped"
android:id="#+id/goodevening" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Please"
android:onClick="buttonTapped"
android:id="#+id/please" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="My name is..."
android:onClick="buttonTapped"
android:id="#+id/mynameis" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Do you
speak English?"
android:onClick="buttonTapped"
android:id="#+id/doyouspeakenglish" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Welcome"
android:onClick="buttonTapped"
android:id="#+id/welcome" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="I live in..."
android:onClick="buttonTapped"
android:id="#+id/ilivein" />
</GridLayout>
</RelativeLayout>
The error is very clear: Just remove the RelativeLayout and try again:
<GridLayout
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">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Hello"
android:onClick="buttonTapped"
android:id="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="How are you?"
android:onClick="buttonTapped"
android:id="#+id/howareyou" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Good Evening"
android:onClick="buttonTapped"
android:id="#+id/goodevening" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Please"
android:onClick="buttonTapped"
android:id="#+id/please" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="My name is..."
android:onClick="buttonTapped"
android:id="#+id/mynameis" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Do you
speak English?"
android:onClick="buttonTapped"
android:id="#+id/doyouspeakenglish" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Welcome"
android:onClick="buttonTapped"
android:id="#+id/welcome" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="I live in..."
android:onClick="buttonTapped"
android:id="#+id/ilivein" />
</GridLayout>
This warning is because your RelativeLayout contains only GridLayout and both (recyclerView and GridLayout) are set to match_parent
You can remove RelativeLayout and set GridLayout as root layout and it will look exactly like now but better for performance.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.jumin.basicphrases.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Hello"
android:onClick="buttonTapped"
android:id="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="How are you?"
android:onClick="buttonTapped"
android:id="#+id/howareyou" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Good Evening"
android:onClick="buttonTapped"
android:id="#+id/goodevening" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Please"
android:onClick="buttonTapped"
android:id="#+id/please" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="My name is..."
android:onClick="buttonTapped"
android:id="#+id/mynameis" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Do you
speak English?"
android:onClick="buttonTapped"
android:id="#+id/doyouspeakenglish" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="Welcome"
android:onClick="buttonTapped"
android:id="#+id/welcome" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:text="I live in..."
android:onClick="buttonTapped"
android:id="#+id/ilivein" />
</GridLayout>