Vera rind February 2016

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?

Answers


Gabe Sechan February 2016

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.


durbnpoisn February 2016

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.


g2o February 2016

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" />


Sabari February 2016

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

Post Status

Asked in February 2016
Viewed 1,445 times
Voted 13
Answered 4 times

Search




Leave an answer