着色“空间”小部件

问题描述:

我正在尝试着色“空间”小部件。我尝试使用android:foregroundandroid:background属性,但仍显示透明视图。着色“空间”小部件

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

空间的目的是**透明**。为什么不使用具有彩色背景的裸视图(或TextView或ImageView或其他)?对于分隔符(这看起来像你愿意实现的用法),我使用裸视图。 –

+1

为什么空间属性不起作用? –

+0

“空间是透明的。”这对调试非常有用,真的...... – AndrewBloom

作为每official docs定义:

空间是可以被用于创建通用布局部件之间的间隙的轻量级查看子类。

他们可能没有想到“着色一个空的空间”。
“空”的意思是“没有颜色”,“不可见”。

这就是我想要做的:

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

使用裸查看分频器是我的2/3裸意见惯用的手段之一。
我也使用它们作为间隔符和RelativeLayouts中的“中心点”。

+0

我知道这件事。我在想如果空间可以着色。 –

+0

看来这是不可能的。该视图将非常好地诀窍。 –

我试过Paul的“查看技巧”,但是GridLayout有水平/垂直约束问题(并且在执行过程中,一旦遇到这个视图,绘图就会停止)。 对我来说(Studio 2.3.3,api 21)这个工作:

<TextView 
     android:layout_width="4dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="fill_vertical" 
     android:background="@color/housetoolsBlue" />