Android 充气布局以查看
我想将视图添加到窗口管理器,此视图必须是我的布局。但是,当我试图膨胀布局,然后添加它,我只能看到我的布局(按钮)的一部分,而不是整个布局。有人能告诉我我做错了什么吗? 我的布局:Android 充气布局以查看,android,Android,我想将视图添加到窗口管理器,此视图必须是我的布局。但是,当我试图膨胀布局,然后添加它,我只能看到我的布局(按钮)的一部分,而不是整个布局。有人能告诉我我做错了什么吗? 我的布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_paren
<?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">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button3"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
你只看到一个按钮,因为我猜,这是你版面中唯一可见的东西。@doug stevenson你知道如何使整个版面可见吗?你的xml版面中只有一个
按钮,你想看到更多吗?@rami Ohh,明白了。但我想看看按钮和背景image@S.Drumble3将背景添加到您的中(android:background=“@drawable/your\u image\u drawable”
)
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater)this.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.launcher_activity,null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT;
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 0;
params.y = 100;
windowManager.addView(v, params);