Android创建全屏相对布局



我想我已经阅读了与此相关的每个问题,但仍然没有找到这种简单需求的解决方案...

我正在创建几个自定义relativelayout,并以编程方式将它们添加到我的窗口中。他们工作得很好,除了他们不涵盖状态栏。当我想展示其中一个时,我只是尝试隐藏状态栏,但是当然,隐藏是动画的,我想避免。

注意:我已经尝试使用" windowmanager.layoutparams.type_system_overlay,而不是type_phone在下面的示例中。。

感谢您的建议!

这是我的自定义relativelayout:

public class MyView extends RelativeLayout {
public MyView(Context context) {
    super(context);
    init(context, null, 0);
}
public MyView(Context context, AttributeSet attrs) {
    super(context,attrs);
    init(context, attrs, 0);
}
public MyView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle)
{
    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
            PixelFormat.TRANSLUCENT);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.my_layout, this, true);
    this.setVisibility(View.GONE);
    WindowManager windowManager = (WindowManager) activity.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    windowManager.addView(this, params);
}
....

这是我的布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:background="#000000"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true">
<ImageView
    android:id="@+id/myImageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:focusable="true"
    android:clickable="true"
    android:focusableInTouchMode="true"
    />
</RelativeLayout>

以全屏模式运行视图。

public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // remove title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
  }
}

在AppCompatactivity的情况下,使用此。

<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

好吧,我试图在没有动画的情况下从现有活动中显示出全屏幕活动,甚至可以使动作栏的隐藏动画。这也有点懒惰。

我在上面的问题上回到创建自定义relativelayout,然后根据需要显示它们。(只有我要显示一个相关性显示之前,我只需要隐藏一个动作栏。(

最新更新