Place text under the image

Asked

Viewed 471 times

1

I’m developing an application and I put an image with a text underneath but when I run the application it looks like, the text next to the image:

<?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:background="@android:color/holo_blue_light"
tools:context="com.example.tulio.myapplication.MainActivity">



<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageView2"
    tools:layout_editor_absoluteY="280dp">


    <TextView
        android:id="@+id/textView2"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:text="@string/alan"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="297dp" />

</ScrollView>


<TextView
    android:id="@+id/txtNome1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:autoText="false"
    android:text="Alan Turing"
    android:textColor="?android:attr/colorActivatedHighlight"
    tools:layout_editor_absoluteX="161dp"
    tools:layout_editor_absoluteY="16dp" />


<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/alan"
    tools:layout_editor_absoluteX="106dp"
    tools:layout_editor_absoluteY="41dp" />

(Color.parseColor("#BABABA")); />

</android.support.constraint.ConstraintLayout>

How was the application

inserir a descrição da imagem aqui

  • by placing all the content inside the Scrollview it error, and the image comes out

  • This layout is not clear to me. 1º I do not understand why two Widgets are out of Scrollview which is Parent Widget, 2º Put all components in a Linearlayout and set the orientation as vertical

  • Opa, puts the image inside a linear_layout and the text inside another linear_layout (this below the image layout), then just set the wrap and match Parent.

  • thanks for the personal tip

2 answers

2

That is the resolution.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtNome1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Alan Turing"
        android:textColor="?android:attr/colorActivatedHighlight"
        android:textSize="30sp"
        android:textStyle="bold" />


    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="300dp"
        android:layout_height="300dp"
        app:srcCompat="@drawable/common_google_signin_btn_icon_dark" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/imageView2">


        <TextView
            android:id="@+id/textView2"
            android:layout_width="368dp"
            android:layout_height="wrap_content"
            android:text="@string/texto_autor" />

    </ScrollView>

</LinearLayout>

inserir a descrição da imagem aqui

2


There are several ways to solve the problem. As for example insert a LinearLayout with vertical orientation. See:

<?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:background="@android:color/holo_blue_light">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txtNome1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:autoText="false"
            android:text="Alan Turing"
            android:textColor="?android:attr/colorActivatedHighlight"
            tools:layout_editor_absoluteX="161dp"
            tools:layout_editor_absoluteY="16dp" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/cast_album_art_placeholder"
            tools:layout_editor_absoluteX="106dp"
            tools:layout_editor_absoluteY="41dp" />

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            tools:layout_editor_absoluteY="280dp">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="368dp"
                android:layout_height="wrap_content"
                android:text="@string/alan"
                tools:layout_editor_absoluteX="8dp"
                tools:layout_editor_absoluteY="297dp" />
        </ScrollView>

    </LinearLayout>

</android.support.constraint.ConstraintLayout>
  • 1

    vlw man worked here thanks for the help

Browser other questions tagged

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