Which is the advantage of using Space over View

时间:2016-08-31 16:53:16

标签: android performance view android-view

I found that I'm using a View to make the space in my layouts and I thought to replace it with a Space.
So I asked myself if is there any gain to replace View with Space to make the space.

Space using the View widget :

<View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        />

Space using the Space widget:

<Space
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        />

So... is there any gain to use the Space view instead of the View for spacing in a layout?

1 个答案:

答案 0 :(得分:10)

For the most part, they're exactly the same. A Space sets its visibility to View#INVISIBLE by default so drawing operations are skipped. Other than that, there isn't much of a difference.