Textview does not appear for some reason

Asked

Viewed 456 times

0

I’d like to do something like this in XML: inserir a descrição da imagem aqui

I’ve tried with Linearlayout but I’m not getting it.

<?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:background="@color/colorBackground"
   android:orientation="vertical"
   android:weightSum="1" >

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10px"
    android:layout_marginTop="10px"
    android:fontFamily="serif"
    android:text="Título Legal"
    android:textColor="@color/colorText"
    android:textSize="40px"
    android:textStyle="bold" />

<LinearLayout
    android:layout_width="280px"
    android:layout_height="400px"
    android:background="@drawable/img1"
    android:orientation="horizontal"
    android:weightSum="1">

    <LinearLayout
        android:layout_width="171dp"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Oie"
            android:textColor="@color/colorText"
            android:layout_marginLeft="281px" />

    </LinearLayout>
</LinearLayout>

If I put the text where the image is, the text appears, but when I try to put it a little in front of the image, it does not appear (android:layout_marginLeft="281px").

Note: The background color is black (@color/colorBackground) and the text color is white (@color/colorText).

1 answer

0


The statement of Android libraries on root of your layout was duplicated and misspelled. I already corrected this in the editing of your post.

But I created a layout new and tested in my app. It’s working the way you want:

inserir a descrição da imagem aqui

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/layout_group"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <LinearLayout
            android:id="@+id/layout_left"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_marginRight="20dp"
            android:gravity="center">
            <ImageView
                android:id="@+id/img1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/icon_alert_error" />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/layout_right"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1">
            <TextView
                android:id="@+id/text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Texto 1" />
            <TextView
                android:id="@+id/text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Texto 2" />
            <TextView
                android:id="@+id/text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Texto 3" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

The image is in the layout_left and the texts in layout_right. The layout_group serves to center the two layouts equally on the screen.

Browser other questions tagged

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