Which is the lightest view?
In Android, Which is the light weight view ? ex:- View, Textview, Edittext, etc....
In some case we need to use a view to fill the area without showing the view to the user. At the same time the screen should load fa开发者_如何学JAVAst.
You can use Space.
android.widget.Space
Space is a lightweight View subclass that may be used to create gaps between components in general purpose layouts.
If by "lightweight" you meant memory footprint, then there is none exists on Android, because each view have to derive from View
, which itself is a massive object (well, not massive, it is about 8kB), so it's not that big.
But in terms of measure, layout and draw time the basic View performs well. You just have to set its visibility to INVISIBLE
. And so it will be measured and put into the layout (contrary to GONE
with which the view would not take up any space).
Unfortunately ViewStub
is not meant to be used for this purpose. Its default visibility is GONE
.
If you are really picky, then you can extend View
and override methods like draw()
(to do nothing, do not even call super), dispatchDraw()
, setVillNotDraw(true)
, etc. (Take ViewStub
as a sample).
You should have a look at ViewStub.
Use ViewStub if it is sufficient or LinearLayout which may be somewhat light weight.
精彩评论