Place gallery with text

Asked

Viewed 147 times

2

I’m trying to put a product gallery in my app, and I wanted the image and the text below, I’m using the viewpager, however the text ta getting on the side, and the images very far away from each other, only appearing an image wanted it to appear at least 2 with the text below. Look at the code:

Viewpagermain

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Item

<TextView
    android:id="@+id/ranklabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/ranklabel" />

<TextView
    android:id="@+id/rank"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/ranklabel" />

<TextView
    android:id="@+id/countrylabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ranklabel"
    android:text="@string/countrylabel" />

<TextView
    android:id="@+id/country"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rank"
    android:layout_toRightOf="@+id/countrylabel" />

<TextView
    android:id="@+id/populationlabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/countrylabel"
    android:text="@string/populationlabel" />

<TextView
    android:id="@+id/population"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/country"
    android:layout_toRightOf="@+id/populationlabel" />

<ImageView
    android:id="@+id/flag"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:background="#000000"
    android:padding="1dp" />

How to put the closest images and the text below?

  • Guys, how do I use the "Execute Code Snippet" function when asking?

  • @Warlock there is a sample app that exemplifies very well what you want, at least that’s what I think you see and tell me if that’s it? https://github.com/googlesamples/android-XYZTouristAttractions download and create your app

1 answer

1

Well... Your question is very vague, but when presenting only XML code, I can answer that there is only one <ImageView , ie ONLY ONE IMAGE. Add one more <ImageView to your xml and for the texts to be below, in column form, remove the android:layout_toRightOf, of <TextView put something like this:

<ImageView
    android:id="@+id/flag"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:padding="1dp" />

<ImageView
    android:id="@+id/flag2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:padding="1dp" />


<TextView
    android:id="@+id/ranklabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/ranklabel" />

<TextView
    android:id="@+id/rank"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<TextView
    android:id="@+id/countrylabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/ranklabel"
    android:text="@string/countrylabel" />

<TextView
    android:id="@+id/country"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rank" />

<TextView
    android:id="@+id/populationlabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/countrylabel"
    android:text="@string/populationlabel" />

<TextView
    android:id="@+id/population"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/country" />

REMEMBERING that it is also necessary to add more Java code for this new Imageview. It is no use just adding this Imageview in XML.

  • Guys, how do I use the "Execute Code Snippet" function when asking?

Browser other questions tagged

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