Positioning of Gridlayout Android images

Asked

Viewed 246 times

0

UPDATE

I am developing a mobile application, using gridLayout and I would like to leave an image on the side of the other, in case the imageView1 on the side of the imageView 2 , underneath imageViem3 on the side of imageView4 but now the image View2, imageView3, imageView4 leave the bounded space for cell screen

inserir a descrição da imagem aqui

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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.tulio.exercicio5.MainActivity">


<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="2"
    android:rowCount="3"
    android:orientation="horizontal">



    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:srcCompat="@drawable/aliados"
        android:layout_column="0"
        android:layout_row="0"
        />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/chamado3"
        android:layout_column="1"
        android:layout_row="0"
        android:layout_gravity="fill_horizontal"
        android:layout_marginRight="290dp"

        />



    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/regresso"
        android:layout_row="1"
        android:layout_column="1"
        />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_gravity="fill_vertical"
        android:layout_row="1"
        app:srcCompat="@drawable/john_wick" />


    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/residentevil6"
        android:layout_below ="@+id/imageView4"/>


    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/xxxreativado"
        android:layout_toLeftOf="@+id/imageView6"/>

</GridLayout>

  • That ain’t cool no. Search on Recyclerview

  • but that wouldn’t be the best way to do what I’m doing using Gridlayout ?

  • Gridlayout will only be valid in this situation if there is no change in the films. If you wanted to change, and insert a new movie, you will have to change the layout again. The interesting thing is you create a list of movies using Recyclerview, so you will make it more dynamic.

  • For example, see this image using Recyclerview + Cardview: https://www.androidhive.info/wp-content/uploads/2016/05/android-integrating-cardview-and-recyclerview-music-app.png

1 answer

1


The width your third Imageview is match_parent , so it takes up the entire width of scrollView

UPDATE: I adjusted the dimensions, lines and columns. Something like:

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:srcCompat="@drawable/aliados"
    android:layout_column="0"
    android:layout_row="0"
    />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/chamado3"
    android:layout_column="1"
    android:layout_row="0"
    />



<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/regresso"
    android:layout_row="1"
    android:layout_column="0"
    />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_column="1"
    android:layout_row="1"
    app:srcCompat="@drawable/john_wick" />


<ImageView
    android:id="@+id/imageView6"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/residentevil6"
    android:layout_column="1"
    android:layout_row="2"/>


<ImageView
    android:id="@+id/imageView7"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/xxxreativado"
    android:layout_column="1"
    android:layout_row="2"/>

  • I changed and the imageView4 was not on the side of the imageView3

  • instead of android:layout_columnSpan in imageViews, use android:layout_column. The columnSpan would be to join columns in a row.

  • i updated the question André Ozawa now that I put as android:layout_column the imageView2,imageView3,imageView4 leave the limited space for celualr screen, I put the image to illustrate and updated my code for you to see

  • Try all widths and lengths of Imageviews as wrap_content. The second Imageview has the property layout_gravity=fill_horizontal, which makes it fill the length.

  • Thank you André Ozawa was just what I had to do

Browser other questions tagged

You are not signed in. Login or sign up in order to post.