0

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?

Sebastian Schumann
  • 3,204
  • 19
  • 37

4 Answers4

1

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.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • No that's not what I'm trying to do. There are some more controls in it. I tried to create some fragments and I tried them to add to a table - but I wasn't able to create a table and add some columns at runtime. – Sebastian Schumann Feb 08 '16 at 19:32
  • Have you tried a TableView? You may have oversimplified your example here. – Gabe Sechan Feb 08 '16 at 19:34
  • I'll try a TableView - thx. I added the sentence _There are much more controls contained but this is enough to demonstrate the problem._ to make clear that there are more controls contained. – Sebastian Schumann Feb 08 '16 at 19:36
1

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

Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
0

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.

durbnpoisn
  • 4,666
  • 2
  • 16
  • 30
  • View is an object. However using one as a spacer usually means that the author is doing something wrong, its a very inefficient way of doing things. It was more frequently used 3 or 4 years ago when people were coming up to speed on the platform. – Gabe Sechan Feb 08 '16 at 19:35
  • @GabeSechan I'm pretty sure that I'm doing something wrong. The problem is that I'm a C# developer but that's the first android program that I'm trying to create. – Sebastian Schumann Feb 08 '16 at 19:39
  • @Verarind Sorry, that wasn't meant as a dig. A lot of old answers will show using a view like that. Its one of those things that works, but was found to be a bad practice over time. You'll still sometimes see it in fast and dirty code though. – Gabe Sechan Feb 08 '16 at 19:42
0

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

Sabari
  • 1,963
  • 1
  • 13
  • 10