我使用View.bringtofront()
中的Activity.onCreate()
将叠加层置于顶部。它除了按钮之外的所有东西! ..任何人都知道为什么会这样?以及如何解决这个问题?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="@+id/tv"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv"
android:text="Click Me"/>
<TextView
android:id="@+id/tv2"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn"/>
</RelativeLayout>
setContentView(R.layout.activity_main);
RelativeLayout root = (RelativeLayout) findViewById(R.id.root);
View overlayView = new View(this);
overlayView.setBackgroundColor(0xCC0000CC);
root.addView(overlayView);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) overlayView.getLayoutParams();
params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
params.width = RelativeLayout.LayoutParams.MATCH_PARENT;
overlayView.bringToFront();
root.requestLayout();
root.invalidate();