安卓:addview() - 增加一个新的视图上的活动之上 [英] Android: addview()- adding a new view on top of activity
本文介绍了安卓:addview() - 增加一个新的视图上的活动之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ImageView的和文本框下面的布局,
I have the following layout with an imageview and textfield,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="26dp"
android:layout_marginTop="22dp"
android:src="@drawable/a01" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView1"
android:layout_marginTop="31dp"
/>
</RelativeLayout>
此布局将是透明的,我希望把这种布局上的一个特定的活动,具体活动刚启动时,如何与实现它addview的顶部()
?
This layout will be transparent and I want to call this layout on top of a particular activity ,when the particular activity first starts, how to implement it with addview()
?
推荐答案
当你要显示它:
FrameLayout rootLayout = (FrameLayout)findViewById(android.R.id.content);
View.inflate(this, R.layout.overlay_layout, rootLayout);
当你要删除它,然后:
FrameLayout rootLayout = (FrameLayout)findViewById(android.R.id.content);
rootLayout.removeViewAt(rootLayout.getChildCount()-1);
这是一个简洁的解决方案,您应该删除查看
通过给 RelativeLayout的
XML文件中的一个id,然后删除: rootLayout.removeView(findViewById(R.id.the_id_of_the_relative_layout));
That's a concise solution, you should remove the View
by giving the RelativeLayout
an id in the XML file, then remove by: rootLayout.removeView(findViewById(R.id.the_id_of_the_relative_layout));
.
这篇关于安卓:addview() - 增加一个新的视图上的活动之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文