Android的覆盖视图ontop的一切? [英] Android overlay a view ontop of everything?
问题描述
您可以覆盖一切的顶视图中的Android?
Can you overlay a view on top of everything in android?
在iPhone我会得到新的视图设置其 frame.origin
来(0,0),其宽度和高度<$ C $的宽度和高度C> self.view 。将它添加到 self.view
然后将导致它作为一个覆盖,覆盖后面的内容(或者,如果它有一个透明的背景则显示视图后面)。
In iPhone I would get the new view set its frame.origin
to (0,0) and its width and height to the width and height of self.view
. Adding it to self.view
would then cause it to act as an overlay, covering the content behind (or if it had a transparent background then showing the view behind).
有没有在Android的类似的技术?我认识到的意见略有不同(有三种类型(或更多...)RelativeLayout的,LinearLayout中和的FrameLayout),但有什么办法,只是覆盖在一切之上的观点胡乱?
Is there a similar technique in android? I realise that the views are slightly different (there are three types (or more...) relativelayout, linearlayout and framelayout) but is there any way to just overlay a view on top of everything indiscriminately?
感谢你。
推荐答案
只需使用 RelativeLayout的
或的FrameLayout
。最后一个子视图将覆盖一切。
Simply use RelativeLayout
or FrameLayout
. The last child view will overlay everything else.
Android支持的模式而可可触摸SDK不:布局管理
布局的为iPhone意味着一切的位置绝对(除了一些STRECH因素)。布局安卓意味着孩子将被放置在关系到海誓山盟。
Android supports a pattern which Cocoa Touch SDK doesn't: Layout management.
Layout for iPhone means to position everything absolute (besides some strech factors). Layout in android means that children will be placed in relation to eachother.
例(第二的EditText将完全覆盖第一个):
Example (second EditText will completely cover the first one):
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/root_view">
<EditText
android:layout_width="fill_parent"
android:id="@+id/editText1"
android:layout_height="fill_parent">
</EditText>
<EditText
android:layout_width="fill_parent"
android:id="@+id/editText2"
android:layout_height="fill_parent">
<requestFocus></requestFocus>
</EditText>
</FrameLayout>
的FrameLayout
是某种观点栈。用于制造特殊情况。
FrameLayout
is some kind of view stack. Made for special cases.
RelativeLayout的
是pretty的强大。你可以这样定义的规则视图A有对齐父布局底部的查看B必须对准底部到顶部的等
RelativeLayout
is pretty powerful. You can define rules like View A has to align parent layout bottom, View B has to align A bottom to top, etc
基于注释更新
通常设置在的onCreate
与的setContentView(R.layout.your_layout)
的内容(它会膨胀布局你)。您为cn做手工,并调用的setContentView(inflatedView)
,有没有什么区别。
Usually you set the content with setContentView(R.layout.your_layout)
in onCreate
(it will inflate the layout for you). You cn do that manually and call setContentView(inflatedView)
, there's no difference.
视图本身可能是单一视图(如的TextView
)或复杂的布局层次结构(嵌套布局,因为所有的布局意见自理)。
The view itself might be single view (like TextView
) or a complex layout hierarchy (nested layouts, since all layouts are views themself).
调用后的setContentView
的活动知道其内容的样子,你可以使用(的FrameLayout)findViewById(R.id.root_view)
检索任何观点int此层次结构(一般模式(ClassOfTheViewWithThisId)findViewById(R.id.declared_id_of_view)
)。
After calling setContentView
your activity knows what its content looks like and you can use (FrameLayout) findViewById(R.id.root_view)
to retrieve any view int this hierarchy (General pattern (ClassOfTheViewWithThisId) findViewById(R.id.declared_id_of_view)
).
这篇关于Android的覆盖视图ontop的一切?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!