Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coloring the Space widget

I am trying to color the Space widget. I tried using both the android:foreground and android:background attributes, but still it is displaying a transparent View.

 <android.support.v4.widget.Space
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:foreground="@android:color/black"
    android:background="@android:color/black" />
like image 553
Malwinder Singh Avatar asked Jan 24 '16 12:01

Malwinder Singh


2 Answers

As per the official docs definition:

Space is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.

They probably didn't think of "coloring an empty space".
Where "empty" means "without color", "invisible".

That's what I'd do:

<View
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@android:color/black"
/>

Using a bare View as a divider is one of my 2/3 favourite tricks with bare Views.
I also use them as spacers and as "center point" in RelativeLayouts.

like image 121
Phantômaxx Avatar answered Oct 16 '22 02:10

Phantômaxx


I tried Paul's "view trick" but had GridLayout horizontal / vertical constraints problem (and during execution drawing stops as soon as this view is encountered). For me (Studio 2.3.3, api 21) this worked :

<TextView
        android:layout_width="4dp"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:background="@color/housetoolsBlue" />
like image 1
malokran Avatar answered Oct 16 '22 00:10

malokran