着色Space小部件

时间:2016-01-24 12:43:27

标签: android android-layout android-widget space

我正在尝试为Space小部件着色。我尝试使用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" />

2 个答案:

答案 0 :(得分:25)

根据official docs定义:

  

Space是一个轻量级的View子类,可用于在通用布局中创建组件之间的间隙。

他们可能没有想到为空白着色&#34; 哪里&#34;空&#34;意味着&#34;没有颜色&#34;,&#34;隐形&#34;。

这就是我要做的事情:

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

使用裸视图作为分隔符是我的2/3最喜欢的技巧之一 我也用它们作为垫片和&#34;中心点&#34;在RelativeLayouts。

答案 1 :(得分:1)

我尝试了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" />