本文介绍了有多少ViewStubs太多对于单个布局的XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件中定义的布局(base_layout.xml <$ C C $>),这可能包含20+ ViewStub 定义除了3-5其他视图这样的的ImageView 的LinearLayout 含3-5 的ImageButton 的意见。

I have a layout defined in an XML file(base_layout.xml) which may contain 20+ ViewStub definitions in addition to 3-5 other views such an ImageView and a LinearLayout containing 3-5 ImageButton views.

我应该关心我在这个布局文件中有多少 ViewStub 意见的地方?

Should i be concerned about how many ViewStub views i place in this layout file?

我读了developer.android网站:

I read on the developer.android site:

一个ViewStub是一个哑巴,重量轻  视图。它没有尺寸,它不  画什么,不参与  在以任何方式的布局。意即  一个ViewStub很便宜  膨胀,很便宜,以保持在  视图层次

是够便宜让他们20+?不是所有的在充气当然,只是1-2的时间。

is it cheap enough to have 20+ of them? not all being inflated of course, just 1-2 at a time.

当我说够便宜或谈话的是有关,我就用户界面的性能。

when i say cheap enough or talk of being concerned, i am regarding performance of the UI

编辑:我所要完成的:创建一个可以骨架为我所有的活动布局的XML文件。在每个活动,我会膨胀正确的 ViewStub 与该活动的布局。既然我已经要求同一个骨架这么多的活动,我想重新使用尽可能多地

edit:what i am trying to accomplish:create a layout XML file which can be the skeleton for all my of activities. in each Activity, i will inflate the correct ViewStub with the activity's layout. Since i have so many activities requiring the same skeleton, i wish to re-use as much as possible

我有一个活动类这几乎是我所有的活动的家长。这个父类调用的setContentView(R.layout.base_layout); 。每个子活动,所有我做的是充气相应的 ViewStub base_layout.xml 。这样做可以让我有一个非常定制UI与我所有的活动布局中使用同一个骨架视图

I have an Activity class which is the parent of almost all of my activities. this parent class calls setContentView(R.layout.base_layout);. for each child activity, all i am doing is inflating the corresponding ViewStub inside base_layout.xml. doing this allows me to have a very customized UI with the same skeleton view used on all of my activity layouts

推荐答案

我不认为你会看到一个大的性能损失。它仍然不是让所有的人从一开始膨胀便宜。

I don't think you'll see a big performance hit. It's still cheaper than having all of them inflated from the begining.

有这么多的存根的缺点是,你可能忽略了整个设计。也许它更有意义将若干意见/项目为一体的ViewGroup。也许你可以解释一下你试图做什么,看看是否有更好的方法去实现它。

The downside of having so many stubs is that you could lose sight of the whole design. Maybe it makes more sense to group several views/items into one viewgroup. Maybe you could explain what you're attempting to do and see if there is a better way to realize it

编辑:而不是有多个ViewStubs其中包括不同的子视图一样好,

edit:Well, instead of having multiple ViewStubs which include different subviews like

<ViewStub android:id="@+id/stub"
           android:inflatedId="@+id/activity1"
           android:layout="@layout/myActivity1"
           />
<ViewStub android:id="@+id/stub2"
           android:inflatedId="@+id/activity2"
           android:layout="@layout/myActivity2"
           />

只是有一个单一的ViewStub并在acitivities的onCreate()做这样的事情

just have a single ViewStub and in your acitivities onCreate() do something like

setContentView(R.layout.base_layout);
ViewStub stub = (ViewStub)findViewById(R.id.stub);

stub.setInflateId(R.id.activity1);
stub.setLayoutResource(R.layout.myActivity2);
stub.inflate();

这样你还是只有一个ViewStub在你base_layout,你可以将安装在code夸大了。

This way you'd still have only one ViewStub in your base_layout, which you could setup in code before inflating.

这篇关于有多少ViewStubs太多对于单个布局的XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 21:43