Connect 3, Tic Tac Toe, Play Again button crashes - android

Created a "Play Again" button which clears all the grids containing crosses and circles so user can play the game again. The issue is Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to androidx.gridlayout.widget.GridLayout
at com.example.glow.MainActivity.playAgain
public void playAgain(View view) {
gameIsActive = true;
LinearLayout layout = (LinearLayout) findViewById(R.id.playAgainLayout);
layout.setVisibility(View.INVISIBLE);
activePlayer = 0;
for (int i = 0; i < gameState.length; i++) {
gameState[i] = 2;
}
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
for (int i = 0; i < gridLayout.getChildCount(); i++) {
((ImageView) gridLayout.getChildAt(i)).setImageResource(0);
}
Tried lots of solutions provided on stackoverflow but none seems to work and also note that I am on Android Studio 4.0.1.
This is my XML file:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/gridLayout"
android:layout_width="415dp"
android:layout_height="858dp"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:background="#drawable/grid"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView15"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginStart="120dp"
android:layout_marginTop="180dp"
android:contentDescription="#string/img"
android:onClick="dropIn"
android:tag="0"
app:layout_constraintBottom_toTopOf="#+id/imageView16"
app:layout_constraintEnd_toStartOf="#+id/playAgainLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView22"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginTop="180dp"
android:layout_marginBottom="55dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="1"
app:layout_constraintBottom_toTopOf="#+id/imageView24"
app:layout_constraintEnd_toStartOf="#+id/imageView21"
app:layout_constraintStart_toEndOf="#+id/imageView15"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView21"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginTop="180dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="2"
app:layout_constraintBottom_toTopOf="#+id/imageView23"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView22"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView16"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginStart="20dp"
android:layout_marginTop="110dp"
android:contentDescription="#string/circle"
android:longClickable="true"
android:onClick="dropIn"
android:tag="3"
app:layout_constraintBottom_toTopOf="#+id/imageView17"
app:layout_constraintEnd_toStartOf="#+id/imageView24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView15" />
<ImageView
android:id="#+id/imageView24"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="350dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageView23"
app:layout_constraintStart_toEndOf="#+id/imageView16"
app:layout_constraintTop_toBottomOf="#+id/imageView22" />
<ImageView
android:id="#+id/imageView23"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="330dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView24"
app:layout_constraintTop_toBottomOf="#+id/imageView21" />
<ImageView
android:id="#+id/imageView17"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageView26"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/playAgainLayout" />
<ImageView
android:id="#+id/imageView26"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginBottom="150dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="7"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/imageView25"
app:layout_constraintStart_toEndOf="#+id/imageView17" />
<ImageView
android:id="#+id/imageView25"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="100dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView26"
app:layout_constraintTop_toBottomOf="#+id/playAgainLayout" />
<LinearLayout
android:id="#+id/playAgainLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="34dp"
android:layout_marginLeft="34dp"
android:layout_marginTop="212dp"
android:layout_marginEnd="34dp"
android:layout_marginRight="34dp"
android:layout_marginBottom="69dp"
android:alpha="1"
android:background="#76FF03"
android:gravity="start|end"
android:orientation="vertical"
android:padding="30dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/imageView25"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="#+id/winnerMessage"
android:layout_width="wrap_content"
android:layout_height="59dp"
android:layout_marginStart="30dp"
android:layout_marginTop="40dp"
android:alpha="1"
android:autofillHints=""
android:clickable="false"
android:contentDescription="#string/message"
android:duplicateParentState="false"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:inputType="textPersonName"
android:textSize="30sp" />
<Button
android:id="#+id/playAgain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="playAgain"
android:text="#string/button" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Seems like you have RelativeLayout here findViewById(R.id.gridLayout), please open the layout XML and check it.

Found the solution guys and thanks for your responses as they gave me hints on what to look into. The issue was in the XML code where for gridlayout I was not using <androidx.gridlayout.widget.GridLayout instead I used the XML I posted in the question. Below is the XML that worked and also did some re-positioning to make it work.
<androidx.gridlayout.widget.GridLayout
android:id="#+id/gridLayout"
android:layout_width="300dp"
android:layout_height="297dp"
android:background="#drawable/grid"
app:columnCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rowCount="3">
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="0"
app:layout_column="0"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="1"
app:layout_column="1"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="2"
app:layout_column="2"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="3"
app:layout_column="0"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="4"
app:layout_column="1"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="5"
app:layout_column="2"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="6"
app:layout_column="0"
app:layout_row="2" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="7"
app:layout_column="1"
app:layout_row="2" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:contentDescription="#string/circle"
android:onClick="dropIn"
android:tag="8"
app:layout_column="2"
app:layout_row="2" />
</androidx.gridlayout.widget.GridLayout>
<LinearLayout
android:id="#+id/playAgainLayout"
android:layout_width="231dp"
android:layout_height="170dp"
android:addStatesFromChildren="false"
android:alpha="1"
android:animationCache="false"
android:background="#FFEB3B"
android:baselineAligned="false"
android:clipToPadding="false"
android:elevation="1dp"
android:gravity="top"
android:measureWithLargestChild="false"
android:orientation="vertical"
android:padding="30dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="#+id/gridLayout"
app:layout_constraintEnd_toStartOf="#+id/gridLayout"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/gridLayout"
app:layout_constraintTop_toBottomOf="#+id/gridLayout">
<TextView
android:id="#+id/winnerMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/textview"
android:textSize="30sp" />
<Button
android:id="#+id/playAgainButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="0dp"
android:onClick="playAgain"
android:text="#string/play_again" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

So error basically tells yous that the layout you are using is androidx layout and you are assigning it to Android layout so to correct it try:
androidx.gridlayout.widget.GridLayout var_name = (GridLayout) findViewById(R.id.gridLayout);
Hence problem will be solved

Related

Widgets changing position in Emulator

Whenever I run this program on Emulator, the positions of the widgets change, I tried changing the emulator, size of the layout(Device For Preview), but it wasn't helpful. Please Help me Out.
One solution I got was by decreasing the size of widgets, and arranging widgets to the top of the layout, but it was very time consuming. Also any widget placed at the bottom of the layout wouldn't even show up in the Emulator.
Layout
Emulator
XML file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".button">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/addition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="76dp"
android:layout_marginEnd="116dp"
android:background="#D2F0FD"
android:padding="15dp"
android:text="10 + 5"
android:textColor="#000000"
android:textSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/scoreBoard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="23dp"
android:layout_marginEnd="273dp"
android:background="#F44336"
android:padding="10dp"
android:text="0/0"
android:textSize="25dp" />
<TextView
android:id="#+id/result"
android:layout_width="183dp"
android:layout_height="61dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="487dp"
android:layout_marginEnd="49dp"
android:layout_marginBottom="92dp"
android:padding="5dp"
android:text="result"
android:textSize="30dp" />
<Button
android:id="#+id/play"
android:layout_width="127dp"
android:layout_height="64dp"
android:layout_marginStart="150dp"
android:layout_marginTop="-417dp"
android:layout_marginEnd="133dp"
android:layout_marginBottom="528dp"
android:onClick="playAgain"
android:text="Play Again!"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="18dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="26dp"
android:background="#FF9800"
android:padding="10dp"
android:text="30s"
android:textSize="25dp" />
<androidx.gridlayout.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="167dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="182dp"
app:columnCount="2"
app:rowCount="2">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#2196F3"
android:onClick="chosAns"
android:tag="1"
android:text="Button"
android:textSize="30dp"
app:layout_column="0"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="0"
app:layout_rowWeight="1" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#E80909"
android:onClick="chosAns"
android:tag="2"
android:text="Button"
android:textSize="30dp"
app:layout_column="1"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="0"
app:layout_rowWeight="1" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#62F806"
android:onClick="chosAns"
android:tag="3"
android:text="Button"
android:textSize="30dp"
app:layout_column="0"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="1"
app:layout_rowWeight="1" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#8448E4"
android:onClick="chosAns"
android:tag="4"
android:text="Button"
android:textSize="30dp"
app:layout_column="1"
app:layout_columnWeight="1"
app:layout_gravity="fill"
app:layout_row="1"
app:layout_rowWeight="1" />
</androidx.gridlayout.widget.GridLayout>
<Button
android:id="#+id/go"
android:layout_width="268dp"
android:layout_height="146dp"
android:layout_marginStart="64dp"
android:layout_marginTop="433dp"
android:background="#3FED46"
android:onClick="hideIt"
android:text="GO!!"
android:textSize="60dp"
android:visibility="invisible" />
</RelativeLayout>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Because you are nesting Constraint Layout with Relative Layout which contains widget that may lead to overflowing.

constraint layout doesn't look the same in different screen

I want my layout to support all screen sizes,I'm using constraint layout,when i run it on different emulators it doesn't look the same,I'm using dp for sizes and margins,note this app have 12 screens so i can't make layout for every screen size, i tried setting the width of first two cardviews to wrap_content but it seems its not working
[![small screen][1]][1]
<androidx.cardview.widget.CardView
android:id="#+id/id_card_timeView"
android:layout_width="326dp"
android:layout_height="72dp"
android:layout_marginStart="18dp"
android:layout_marginTop="11dp"
android:layout_marginEnd="16dp"
app:cardBackgroundColor="#ff1972a0"
app:cardCornerRadius="39dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView8">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="149dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="145dp"
android:layout_marginBottom="3dp"
android:text="10"
android:textColor="#fff"
android:textSize="27sp" />
<TextView
android:layout_width="32dp"
android:layout_height="58dp"
android:layout_marginStart="90dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="204dp"
android:layout_marginBottom="3dp"
android:text="09"
android:textColor="#fff"
android:textSize="27sp" />
<TextView
android:layout_width="159dp"
android:layout_height="26dp"
android:layout_marginStart="92dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="94dp"
android:layout_marginBottom="46dp"
android:maxLines="1"
android:text="time until next session"
android:textAllCaps="true"
android:textColor="#fff"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="203dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="91dp"
android:layout_marginBottom="3dp"
android:text="23"
android:textColor="#fff"
android:textSize="27sp" />
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/textView2"
android:layout_width="62dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="18dp"
android:layout_marginEnd="278dp"
android:text="OVERVIEW"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/id_card_timeView" />
<View
android:id="#+id/view7"
android:layout_width="327dp"
android:layout_height="1dp"
android:layout_marginStart="17dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="16dp"
android:background="#707070ff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView13" />
<View
android:id="#+id/view6"
android:layout_width="327dp"
android:layout_height="1dp"
android:layout_marginStart="17dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="16dp"
android:background="#707070ff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<View
android:id="#+id/view8"
android:layout_width="327dp"
android:layout_height="1dp"
android:layout_marginStart="17dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="16dp"
android:background="#707070ff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/id_reviews" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginTop="27dp"
android:layout_marginEnd="296dp"
android:text="ORDERS"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/id_card_pagView" />
<androidx.cardview.widget.CardView
android:id="#+id/id_card_orderSmall"
android:layout_width="wrap_content"
android:layout_height="133dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/id_card_earning">
<ImageView
android:id="#+id/imageView9"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="12dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/order_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="67dp"
android:layout_marginEnd="99dp"
android:layout_marginBottom="40dp"
android:text="ORDER"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
<TextView
android:id="#+id/id_order_txt"
android:layout_width="50dp"
android:layout_height="49dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="18dp"
android:layout_marginTop="81dp"
android:layout_marginEnd="104dp"
android:layout_marginBottom="3dp"
android:text="44"
android:textColor="#ff565659"
android:textSize="30sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/id_card_pagView"
android:layout_width="wrap_content"
android:layout_height="133dp"
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/card_cut"
app:layout_constraintEnd_toStartOf="#+id/id_card_orderSmall"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/id_sale_card">
<ImageView
android:id="#+id/imageView6"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="25dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/pageview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="67dp"
android:layout_marginEnd="75dp"
android:layout_marginBottom="40dp"
android:text="PAGE VIEW"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
<TextView
android:id="#+id/id_pageView_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginTop="81dp"
android:layout_marginEnd="85dp"
android:layout_marginBottom="3dp"
android:text="99k"
android:textColor="#ff565659"
android:textSize="30sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/id_sale_card"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginStart="18dp"
android:layout_marginTop="#dimen/_19sdp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toStartOf="#+id/id_card_earning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view6">
<ImageView
android:id="#+id/imageView4"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="25dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/sale" />
<TextView
android:id="#+id/id_sale_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="19dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="98dp"
android:layout_marginBottom="11dp"
android:text="$0.00"
android:textColor="#ff565659" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="18dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="109dp"
android:layout_marginBottom="31dp"
android:text="Sale"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/id_card_earning"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginStart="16dp"
android:layout_marginTop="#dimen/_19sdp"
android:layout_marginEnd="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/id_sale_card"
app:layout_constraintTop_toBottomOf="#+id/view6">
<ImageView
android:id="#+id/imageView8"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="15dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/earning" />
<TextView
android:id="#+id/id_earning_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="19dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="98dp"
android:layout_marginBottom="11dp"
android:text="$0.00"
android:textColor="#ff565659" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="18dp"
android:layout_marginTop="15dp"
android:maxLines="1"
android:text="Earning"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/id_reviews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="19dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="289dp"
android:layout_marginBottom="10dp"
android:text="REVIEWS"
android:textAllCaps="true"
app:layout_constraintBottom_toTopOf="#id/id_card_reviewBig"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/id_card_orderBig" />
<androidx.cardview.widget.CardView
android:id="#+id/id_card_orderBig"
android:layout_width="326dp"
android:layout_height="253dp"
android:layout_marginStart="18dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.549"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view7">
<TextView
android:id="#+id/id_cardTxt_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="21dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="205dp"
android:text="Total"
android:textColor="#ff565659" />
<TextView
android:id="#+id/completed_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="53dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="174dp"
android:text="Completed"
android:textColor="#ff1e9b37" />
<TextView
android:id="#+id/pending_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="85dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="110dp"
android:text="Pending"
android:textColor="#ff949494" />
<TextView
android:id="#+id/processing_txt"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="117dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="205dp"
android:text="Processing"
android:textColor="#ff6c6ca7" />
<TextView
android:id="#+id/cancelled_txt"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="149dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="205dp"
android:text="Cancelled"
android:textColor="#fff33d3d" />
<TextView
android:id="#+id/refunded_txt"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="181dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="205dp"
android:text="Refunded"
android:textColor="#ffd6d61a" />
<TextView
android:id="#+id/onHold_txt"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="213dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="205dp"
android:text="On Hold"
android:textColor="#ffbf7f0f" />
<TextView
android:id="#+id/id_txt_total_bigCard"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="283dp"
android:layout_marginTop="21dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="206dp"
android:text="100"
android:textColor="#ff565659" />
<TextView
android:id="#+id/id_txt_completed_bigCard"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="283dp"
android:layout_marginTop="53dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="206dp"
android:text="100"
android:textColor="#ff1e9b37" />
<TextView
android:id="#+id/id_txt_pending_bigCard"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="283dp"
android:layout_marginTop="85dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="206dp"
android:text="100"
android:textColor="#ff949494" />
<TextView
android:id="#+id/id_txt_processing_bigCard"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="283dp"
android:layout_marginTop="117dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="206dp"
android:text="100"
android:textColor="#ff6c6ca7" />
<TextView
android:id="#+id/id_txt_cancelled_bigCard"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="283dp"
android:layout_marginTop="149dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="206dp"
android:text="100"
android:textColor="#fff33d3d" />
<TextView
android:id="#+id/id_txt_refunded_bigCard"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="283dp"
android:layout_marginTop="181dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="206dp"
android:text="100"
android:textColor="#ffd6d61a" />
<TextView
android:id="#+id/id_txt_onHold_bigCard"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="283dp"
android:layout_marginTop="213dp"
android:layout_marginEnd="10dp"
android:text="100"
android:textColor="#ffbf7f0f" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/id_card_reviewBig"
android:layout_width="326dp"
android:layout_height="173dp"
android:layout_marginStart="18dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="13dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.549"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view8">
<TextView
android:id="#+id/id_cardTxt_totalReviews"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="21dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="205dp"
android:text="Total"
android:textColor="#ff565659" />
<TextView
android:id="#+id/id_cardTxt_liveReviews"
android:layout_width="wrap_content"
android:layout_height="26dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="53dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="174dp"
android:text="Live"
android:textColor="#ff565659" />
</androidx.cardview.widget.CardView>
[1]: https://i.stack.imgur.com/WsrEo.png
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff5f5f5">
<androidx.cardview.widget.CardView
android:id="#+id/id_sale_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toStartOf="#+id/id_card_earning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view6">
<androidx.cardview.widget.CardView
android:id="#+id/id_card_earning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="189dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view6">
Keep UI like this and use below libs
Intuit SSP
Intuit SDP
It's true that #Venky answered, but in my answer, I want to explain why your layout is not looking the same on all devices:
In Android, you need to consider the number of different screen sizes when developing an android application.
Different phones got different screen size, in your layout you are using fixed size on your view (fixed size is android:layout_width="155dp" for example) and the result is that what may look good on one screen (your android studio preview screen)but will not look good on another screen (your actual phone).
A simple solution will be to make the width of your views as match_parent (so it will spread all over the screen) and the height of your views as wrap_content
something like this:
<androidx.cardview.widget.CardView
android:id="#+id/id_sale_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toStartOf="#+id/id_card_earning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view6">
<androidx.cardview.widget.CardView
android:id="#+id/id_card_earning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view6">
Edit:
This is my new layout using Guidelines:
<?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">
<android.support.v7.widget.CardView
android:id="#+id/id_card_timeView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:cardBackgroundColor="#ff1972a0"
app:cardCornerRadius="39dp"
app:layout_constraintBottom_toTopOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="149dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="145dp"
android:layout_marginBottom="3dp"
android:text="10"
android:textColor="#fff"
android:textSize="27sp" />
<TextView
android:layout_width="32dp"
android:layout_height="58dp"
android:layout_marginStart="90dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="204dp"
android:layout_marginBottom="3dp"
android:text="09"
android:textColor="#fff"
android:textSize="27sp" />
<TextView
android:layout_width="159dp"
android:layout_height="26dp"
android:layout_marginStart="92dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="94dp"
android:layout_marginBottom="46dp"
android:maxLines="1"
android:text="time until next session"
android:textAllCaps="true"
android:textColor="#fff"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="203dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="91dp"
android:layout_marginBottom="3dp"
android:text="23"
android:textColor="#fff"
android:textSize="27sp" />
</android.support.v7.widget.CardView>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OVERVIEW"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="#+id/id_sale_card"
app:layout_constraintStart_toStartOf="#+id/id_card_timeView"
app:layout_constraintTop_toBottomOf="#+id/id_card_timeView" />
<View
android:id="#+id/view7"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#707070ff"
app:layout_constraintBottom_toTopOf="#+id/id_card_orderBig"
app:layout_constraintEnd_toEndOf="#+id/id_card_timeView"
app:layout_constraintStart_toStartOf="#+id/id_card_timeView"
app:layout_constraintTop_toBottomOf="#+id/textView13" />
<View
android:id="#+id/view6"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#707070ff"
app:layout_constraintBottom_toTopOf="#+id/id_card_pagView"
app:layout_constraintEnd_toEndOf="#+id/id_card_timeView"
app:layout_constraintStart_toStartOf="#+id/id_card_timeView"
app:layout_constraintTop_toBottomOf="#+id/id_sale_card" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDERS"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp"
app:layout_constraintBottom_toTopOf="#+id/view7"
app:layout_constraintStart_toStartOf="#+id/id_card_timeView"
app:layout_constraintTop_toBottomOf="#+id/id_card_pagView" />
<android.support.v7.widget.CardView
android:id="#+id/id_card_orderSmall"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/view7"
app:layout_constraintEnd_toEndOf="#+id/id_card_timeView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/id_card_pagView"
app:layout_constraintTop_toBottomOf="#+id/id_card_earning">
<ImageView
android:id="#+id/imageView9"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="12dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/order_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="67dp"
android:layout_marginEnd="99dp"
android:layout_marginBottom="40dp"
android:text="ORDER"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
<TextView
android:id="#+id/id_order_txt"
android:layout_width="50dp"
android:layout_height="49dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="18dp"
android:layout_marginTop="81dp"
android:layout_marginEnd="104dp"
android:layout_marginBottom="3dp"
android:text="44"
android:textColor="#ff565659"
android:textSize="30sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/id_card_pagView"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#drawable/card_cut"
app:layout_constraintBottom_toTopOf="#+id/textView13"
app:layout_constraintEnd_toStartOf="#+id/id_card_orderSmall"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/id_card_timeView"
app:layout_constraintTop_toBottomOf="#+id/view6">
<ImageView
android:id="#+id/imageView6"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="25dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/pageview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginTop="67dp"
android:layout_marginEnd="75dp"
android:layout_marginBottom="40dp"
android:text="PAGE VIEW"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
<TextView
android:id="#+id/id_pageView_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="20dp"
android:layout_marginTop="81dp"
android:layout_marginEnd="85dp"
android:layout_marginBottom="3dp"
android:text="99k"
android:textColor="#ff565659"
android:textSize="30sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/id_sale_card"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/view6"
app:layout_constraintEnd_toStartOf="#+id/id_card_earning"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="#+id/id_card_timeView"
app:layout_constraintTop_toBottomOf="#+id/textView2">
<ImageView
android:id="#+id/imageView4"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="25dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/sale" />
<TextView
android:id="#+id/id_sale_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="19dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="98dp"
android:layout_marginBottom="11dp"
android:text="$0.00"
android:textColor="#ff565659" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="18dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="109dp"
android:layout_marginBottom="31dp"
android:text="Sale"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/id_card_earning"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/id_card_orderSmall"
app:layout_constraintEnd_toEndOf="#+id/id_card_timeView"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/id_sale_card"
app:layout_constraintTop_toBottomOf="#+id/id_card_timeView">
<ImageView
android:id="#+id/imageView8"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="101dp"
android:layout_marginTop="15dp"
android:background="#drawable/card_images"
android:scaleType="center"
android:src="#drawable/earning" />
<TextView
android:id="#+id/id_earning_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="19dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="98dp"
android:layout_marginBottom="11dp"
android:text="$0.00"
android:textColor="#ff565659" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="18dp"
android:layout_marginTop="15dp"
android:maxLines="1"
android:text="Earning"
android:textAllCaps="true"
android:textColor="#ff565659"
android:textSize="12sp" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/id_card_orderBig"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/id_card_timeView"
app:layout_constraintStart_toStartOf="#+id/id_card_timeView"
app:layout_constraintTop_toBottomOf="#+id/view7">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/completed_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="Completed"
android:textColor="#ff1e9b37"
app:layout_constraintBottom_toTopOf="#+id/processing_txt"
app:layout_constraintStart_toStartOf="#+id/onHold_txt"
app:layout_constraintTop_toBottomOf="#+id/onHold_txt" />
<TextView
android:id="#+id/pending_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="Pending"
android:textColor="#ff949494"
app:layout_constraintBottom_toTopOf="#+id/refunded_txt"
app:layout_constraintStart_toStartOf="#+id/onHold_txt"
app:layout_constraintTop_toBottomOf="#+id/cancelled_txt" />
<TextView
android:id="#+id/processing_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="Processing"
android:textColor="#ff6c6ca7"
app:layout_constraintBottom_toTopOf="#+id/cancelled_txt"
app:layout_constraintStart_toStartOf="#+id/onHold_txt"
app:layout_constraintTop_toBottomOf="#+id/completed_txt" />
<TextView
android:id="#+id/cancelled_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="Cancelled"
android:textColor="#fff33d3d"
app:layout_constraintBottom_toTopOf="#+id/pending_txt"
app:layout_constraintStart_toStartOf="#+id/onHold_txt"
app:layout_constraintTop_toBottomOf="#+id/processing_txt" />
<TextView
android:id="#+id/refunded_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="Refunded"
android:textColor="#ffd6d61a"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/onHold_txt"
app:layout_constraintTop_toBottomOf="#+id/pending_txt" />
<TextView
android:id="#+id/onHold_txt"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="On Hold"
android:textColor="#ffbf7f0f"
app:layout_constraintBottom_toTopOf="#+id/completed_txt"
app:layout_constraintEnd_toStartOf="#+id/guideline7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/id_txt_total_bigCard"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="100"
android:textColor="#ff565659"
app:layout_constraintBottom_toTopOf="#+id/id_txt_processing_bigCard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline7"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/id_txt_completed_bigCard"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="100"
android:textColor="#ff1e9b37"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/id_txt_pending_bigCard"
app:layout_constraintStart_toStartOf="#+id/id_txt_pending_bigCard"
app:layout_constraintTop_toBottomOf="#+id/id_txt_pending_bigCard" />
<TextView
android:id="#+id/id_txt_pending_bigCard"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="100"
android:textColor="#ff949494"
app:layout_constraintBottom_toTopOf="#+id/id_txt_completed_bigCard"
app:layout_constraintEnd_toEndOf="#+id/id_txt_refunded_bigCard"
app:layout_constraintStart_toStartOf="#+id/id_txt_refunded_bigCard"
app:layout_constraintTop_toBottomOf="#+id/id_txt_refunded_bigCard" />
<TextView
android:id="#+id/id_txt_processing_bigCard"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="100"
android:textColor="#ff6c6ca7"
app:layout_constraintBottom_toTopOf="#+id/id_txt_cancelled_bigCard"
app:layout_constraintEnd_toEndOf="#+id/id_txt_total_bigCard"
app:layout_constraintStart_toStartOf="#+id/id_txt_total_bigCard"
app:layout_constraintTop_toBottomOf="#+id/id_txt_total_bigCard" />
<TextView
android:id="#+id/id_txt_cancelled_bigCard"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="100"
android:textColor="#fff33d3d"
app:layout_constraintBottom_toTopOf="#+id/id_txt_onHold_bigCard"
app:layout_constraintEnd_toEndOf="#+id/id_txt_total_bigCard"
app:layout_constraintStart_toStartOf="#+id/id_txt_total_bigCard"
app:layout_constraintTop_toBottomOf="#+id/id_txt_processing_bigCard" />
<TextView
android:id="#+id/id_txt_refunded_bigCard"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="100"
android:textColor="#ffd6d61a"
app:layout_constraintBottom_toTopOf="#+id/id_txt_pending_bigCard"
app:layout_constraintEnd_toEndOf="#+id/id_txt_total_bigCard"
app:layout_constraintStart_toStartOf="#+id/id_txt_total_bigCard"
app:layout_constraintTop_toBottomOf="#+id/id_txt_onHold_bigCard" />
<TextView
android:id="#+id/id_txt_onHold_bigCard"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:text="100"
android:textColor="#ffbf7f0f"
app:layout_constraintBottom_toTopOf="#+id/id_txt_refunded_bigCard"
app:layout_constraintEnd_toEndOf="#+id/id_txt_total_bigCard"
app:layout_constraintStart_toStartOf="#+id/id_txt_total_bigCard"
app:layout_constraintTop_toBottomOf="#+id/id_txt_cancelled_bigCard" />
<android.support.constraint.Guideline
android:id="#+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="163dp"
app:layout_constraintGuide_percent=".56" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
He is how it will look:

Get ImageView child from GridLayout and clear them?

I am trying to build Tic Tac Toe app using a tutorial.I am stuck at one part.I have a GridLayout having 9 ImageView in 3 rows and 3 column.Have a look at my activity_main xml file
<?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=".MainActivity">
<android.support.v7.widget.GridLayout
android:id="#+id/gridLayout"
android:layout_width="315dp"
android:layout_height="333dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/matrix"
app:columnCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.454"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.562"
app:rowCount="3">
<ImageView
android:id="#+id/imageView1"
android:layout_width="82dp"
android:layout_height="70dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="10dp"
android:onClick="onclick"
android:tag="0"
app:layout_column="0"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="130dp"
android:layout_height="73dp"
android:layout_marginTop="15dp"
android:onClick="onclick"
android:tag="1"
app:layout_column="1"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="87dp"
android:layout_height="74dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:onClick="onclick"
android:tag="2"
app:layout_column="2"
app:layout_row="0" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="82dp"
android:layout_height="70dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="10dp"
android:onClick="onclick"
android:tag="3"
app:layout_column="0"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="130dp"
android:layout_height="73dp"
android:layout_marginTop="15dp"
android:onClick="onclick"
android:tag="4"
app:layout_column="1"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="87dp"
android:layout_height="74dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:onClick="onclick"
android:tag="5"
app:layout_column="2"
app:layout_row="1" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="82dp"
android:layout_height="70dp"
android:layout_marginTop="22dp"
android:layout_marginBottom="10dp"
android:onClick="onclick"
android:tag="6"
app:layout_column="0"
app:layout_row="2" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="130dp"
android:layout_height="73dp"
android:layout_marginTop="20dp"
android:onClick="onclick"
android:tag="7"
app:layout_column="1"
app:layout_row="2" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="87dp"
android:layout_height="74dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="15dp"
android:onClick="onclick"
android:tag="8"
app:layout_column="2"
app:layout_row="2" />
</android.support.v7.widget.GridLayout>
<LinearLayout
android:id="#+id/linearlayout"
android:layout_width="276dp"
android:layout_height="176dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="#color/colorPrimary"
android:orientation="vertical"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.355">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="93dp"
android:text="TextView"
android:textSize="20sp" />
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="70dp"
android:onClick="playagain"
android:text="#string/button"
android:textSize="24sp" />
</LinearLayout>
To empty the already drawn image in GridLayout I used this.But the app's getting crashed can anyone tell me if it's correct
enter code here
public void playagain(View view)
{
GridLayout gridLayout = (GridLayout)findViewById(R.id.gridLayout);
for (int i = 0; i< gridLayout.getChildCount(); i++)
{
((ImageView)gridLayout.getChildAt(i)).setImageResource(0);
}
}
Here's the image of my logcat
You have to import android.support.v7.widget.GridLayout instead of importing android.widget.GridLayout in your class.
Sup?
You can try to change your code from
GridLayout gridLayout = (GridLayout)findViewById(R.id.gridLayout);
to
android.support.v7.widget.GridLayout gridLayout = (android.support.v7.widget.GridLayout)findViewById(R.id.gridLayout);
Use
android.support.v7.widget.GridLayout
instead of
GridLayout

My Android layout design is not on the same placement when running it on emulator, and shows them incorrect positioned

I am using Android 2.3.3 version and making a tic tac toe game on it. I am having a problem with a placement of objects when designing the layout, and also there is something wrong with a game state of the game.
Any help would be great !
look below image of my layout
Here is my xml code:
<?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.sherzod.ion.tictactoeandroid.MainActivity">
<GridLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="46dp"
android:layout_marginEnd="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginStart="1dp"
android:layout_marginTop="46dp"
android:background="#drawable/board"
android:columnCount="3"
android:rowCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<ImageView
android:id="#+id/imageView"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="0"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_row="0"
android:onClick="dropIn"
android:tag="0" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="1"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_row="0"
android:onClick="dropIn"
android:tag="1"/>
<ImageView
android:id="#+id/imageView6"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="2"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_row="0"
android:onClick="dropIn"
android:tag="2"/>
<ImageView
android:id="#+id/imageView9"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="0"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="40dp"
android:layout_row="1"
android:onClick="dropIn"
android:tag="3"/>
<ImageView
android:id="#+id/imageView10"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="1"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="40dp"
android:layout_row="1"
android:onClick="dropIn"
android:tag="4"
tools:ignore="RtlHardcoded" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="2"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:layout_row="1"
android:onClick="dropIn"
android:tag="5" />
<ImageView
android:id="#+id/imageView12"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="0"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:layout_row="2"
android:onClick="dropIn"
android:tag="6"/>
<ImageView
android:id="#+id/imageView14"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="2"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:layout_row="2"
android:onClick="dropIn"
android:tag="7"/>
<ImageView
android:id="#+id/imageView13"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="1"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:layout_row="2"
android:onClick="dropIn"
android:tag="8"/>
</GridLayout>
</android.support.constraint.ConstraintLayout>
Here is my Main Activity file:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
// 0 = yellow ; 1 = red;
int activePlayer = 0;
// ** 2 means unplayed
int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2};
public void dropIn(View view) {
ImageView counter = (ImageView) view;
System.out.println(counter.getTag().toString());
int tappedCounter = Integer.parseInt(counter.getTag().toString());
if(gameState[tappedCounter] == 2) {
gameState[tappedCounter] = activePlayer;
}
counter.setTranslationY(-1000f);
if(activePlayer == 0) {
counter.setImageResource(R.drawable.yellow);
activePlayer = 1;
}else {
counter.setImageResource(R.drawable.red);
activePlayer = 0;
}
counter.animate().translationYBy(1000f).rotation(360).setDuration(200);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I have made a few changes to your layout:
Added columnWeight and rowWeight to each grid item
Added layout_gravity fill to each grid item
Check the below 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">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/board"
android:layout_marginBottom="46dp"
android:layout_marginEnd="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginStart="1dp"
android:layout_marginTop="46dp"
android:columnCount="3"
android:rowCount="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1">
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="0" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="1" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="2" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="40dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="3" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="40dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="4"
tools:ignore="RtlHardcoded" />
<ImageView
android:id="#+id/imageView11"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="5" />
<ImageView
android:id="#+id/imageView12"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginLeft="10dp"
android:layout_marginTop="50dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="6" />
<ImageView
android:id="#+id/imageView14"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="7" />
<ImageView
android:id="#+id/imageView13"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:layout_marginLeft="20dp"
android:layout_marginTop="50dp"
android:onClick="dropIn"
android:src="#mipmap/ic_launcher"
android:tag="8" />
</GridLayout>
</android.support.constraint.ConstraintLayout>

RecyclerView scrolls slowly and with lag on Samsung note 4

I have a RecyclerView that each row of that has a GridLayout. I inserted some rows (about 10) in the RecyclerView. It scrolls smoothly in Nexus 5 and Nexus 7 and Sony. But when I run it on Samsung Note 4, it scrolls very slowly and with lots of lag!!
This is my layout for each row:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.GridLayout
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:padding="16dp"
app:orientation="vertical"
app:columnCount="4"
>
<TextView
android:id="#+id/start_time_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="left|center_vertical"
app:layout_row="0"
app:layout_column="0"
android:textAppearance="#style/TextAppearance.AppCompat.Caption"
android:text="test"
/>
<View
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_row="0"
app:layout_column="1"
app:layout_rowSpan="3"
app:layout_gravity="fill"
android:background="#color/dim_foreground_disabled_material_dark"
/>
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_row="0"
app:layout_column="2"
android:singleLine="true"
app:layout_gravity="right|center_vertical|fill"
android:textAppearance="#style/TextAppearance.AppCompat.Title"
android:ellipsize="end"
android:layout_margin="10dp"
android:text="test"
/>
<ImageView
android:id="#+id/event_icon"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_row="0"
app:layout_column="3"
app:layout_gravity="center_vertical"
android:src="#mipmap/ic_launcher"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_row="1"
app:layout_column="1"
app:layout_columnSpan="2"
app:layout_gravity="center_horizontal|center_vertical"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="center_horizontal|center_vertical|fill"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/button_material_dark"
android:layout_margin="6dp"
android:text="test"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="25dp"
android:layout_height="25dp"
app:layout_gravity="center_horizontal|center_vertical"
android:src="#mipmap/ic_supervisor_account_black_24dp"/>
</LinearLayout>
<TextView
android:id="#+id/end_time_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_row="2"
app:layout_column="0"
app:layout_gravity="left|center_vertical"
android:paddingRight="10dp"
android:textAppearance="#style/TextAppearance.AppCompat.Caption"
android:text="test"
/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_row="2"
app:layout_column="2"
app:layout_gravity="right|center_vertical"
android:textAppearance="#style/TextAppearance.AppCompat.Caption"
android:textColor="#color/button_material_dark"
android:layout_margin="10dp"
android:text="test"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="15dp"
android:layout_height="15dp"
app:layout_gravity="center_vertical"
app:layout_row="2"
app:layout_column="3"
android:src="#mipmap/location"/>
<ProgressBar
android:id="#+id/time_progressbar"
app:layout_row="3"
app:layout_column="0"
app:layout_columnSpan="3"
app:layout_gravity="fill"
android:max="100"
android:progress="100"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false" />
<TextView
android:id="#+id/time_text_view"
app:layout_row="3"
app:layout_column="3"
app:layout_gravity="right|center_vertical|fill"
android:textAppearance="#style/TextAppearance.AppCompat.Caption"
android:text="test"
/>
</android.support.v7.widget.GridLayout>
How can I fix this problem?

Categories

Resources