Aditya Deshwal
Aditya Deshwal

Reputation: 35

Views are not aligned properly in custom gridview layout

No aligned properly cstm_grd_layout.xml it is the custom grid view that will be used to show photo and name of each photo it contains ian imageview and an textview

<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent">

    <ImageView
        android:id="@+id/iconImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp"
        android:text="Name"
        android:textSize="24dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/iconImage" />

</androidx.constraintlayout.widget.ConstraintLayout>

activity_main.xml this layout contains the name of the app in textview as id = "VolumeCalculator" and it also contains gridview which will show cstm_grd_layout by the custom adapter class and an viewholder class.

<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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/VolumeCaluclator"
        android:textSize="23dp"
        android:text="Volume Calculator"
        android:gravity="center_horizontal"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        />


    <GridView
        android:id="@+id/shpGridView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

I want both columns to be symmetrical to each other but it is not happening. i think it is due to cstm_grd_layout.xml but i don't know how and why it's doing it and suggestions why ?

Upvotes: 0

Views: 38

Answers (0)

Related Questions