Sebastian Schumann
Sebastian Schumann

Reputation: 3446

LinearLayout doesn't show view

I'm using a LinearLayout that doesn't show every view.

This is the xml-code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="160dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    tools:context="de.schumann_connection.yahtzee.DescriptionColumnFragment">

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="#FF000000" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        tools:context="de.schumann_connection.yahtzee.DescriptionColumnFragment">

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#FF000000" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="43dp"
            android:text=""/>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#FF000000" />
    </LinearLayout>

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="#FF000000" />
</LinearLayout>

There are much more controls contained but this is enough to demonstrate the problem.

This should draw a black rectangle. But the right vertical line is missing. Why?

Upvotes: 0

Views: 1488

Answers (4)

Sabari
Sabari

Reputation: 1981

You have set view background color as transparency "android:background="#FF000000"" replace the color code "android:background="#FF0000""

Upvotes: 0

Gueorgui Obregon
Gueorgui Obregon

Reputation: 5087

Just add weight to the inner LinearLayout android:layout_width="0dp" and android:layout_weight="1"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="#FF000000" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#FF000000" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="43dp"
        android:text="Hola"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#FF000000" />
</LinearLayout>

<View
    android:layout_width="1dp"
    android:layout_marginRight="5dp"
    android:layout_height="match_parent"
    android:background="#FF000000" />

Upvotes: 1

durbnpoisn
durbnpoisn

Reputation: 4669

I don't think "view" is even an object.

It looks like you would rather have a relative view, or maybe a textView or imageView.

In any case, the reason it's not showing up is because that thing doesn't exist.

Upvotes: 0

Gabe Sechan
Gabe Sechan

Reputation: 93561

THis is the wrong way to do what you're trying to do. You want a text view with a black background around it? Just add padding to your TextView on all sides and set the background color.

Upvotes: 1

Related Questions