image view and text view side by side in linear layout

Asked

Viewed 738 times

0

I have to put the image and the text side by side but do not know how to do, my code for now:

<?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="costamilam.guilherme.contatosempresariais.TelaAjuda">

<ScrollView
    android:id="@+id/sv_help"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    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">

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

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="143dp"
            android:layout_height="250dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/shape"
            android:elevation="0dp"
            android:paddingBottom="2dp"
            android:paddingTop="2dp"
            app:srcCompat="@drawable/main_activity"
            android:layout_gravity="left" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="227dp"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:layout_weight="0.96"
            android:text="TextView"
            tools:text="@string/tv_introducao" />

    </LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>

1 answer

2


Exchange the orientation of LinearLayout for horizontal (android:orientation="horizontal"), if you want each item to take up half the screen android:layout_weight of both with the value 1 (sets the "weight" of each view as I understand it). If you want to put other views below you can make a LinearLayout vertically and inside the LinearLayout horizontally

  • function, thanks a lot

Browser other questions tagged

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