以编程方式添加片段并设置其位置

时间:2017-06-05 19:28:13

标签: android

我有一个FrameLayout,我以编程方式在其上绘制一些东西(FullScreen)。这意味着我在>>> def foo(arg): def bar(): arg += 1 return arg return bar >>> >>> foo(0)() # this will raise an error Traceback (most recent call last): File "<pyshell#76>", line 1, in <module> foo(0)() # this will raise an error File "<pyshell#74>", line 3, in bar arg += 1 UnboundLocalError: local variable 'arg' referenced before assignment >>> >>> def foo(arg): def bar(): nonlocal arg arg += 1 return arg return bar >>> foo(0)() # this will work 1 >>> 文件中添加的每个元素都将重叠。所以我想我可以像这样添加xml

Fragment

但我无法找到将片段置于某个位置的方法(在本例中为Center Bottom)。我也无法在 FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout); CustomPlayView customPlayView = new CustomPlayView(getApplicationContext()); frameLayout.addView(customPlayView); FragmentManager fragMan = getFragmentManager(); FragmentTransaction fragTrans = fragMan.beginTransaction(); Fragment myFrag = new PlayerInfoFragment(); fragTrans.add(R.id.fragment,myFrag,"playerInfoFragment"); fragTrans.commit(); 文件中定义Fragment,因为它会与我使用的xml重叠。

有什么想法吗?

0 个答案:

没有答案