TextViews未显示在启用了沉浸式模式的VideoView之上(Android)



我正在开发一个应用程序,将显示视频作为"背景",并有文本和其他视图在它的顶部(使用framayout)。

由于某种原因,当启用沉浸式模式时,我用来测试的textview消失了,尽管在滑动显示系统导航/状态栏时它确实会重新出现。

下面是我的代码:
public class MainActivity extends Activity{
    private Uri video;
    private PowerManager.WakeLock wl;
    private FrameLayout frame;
    private TextView text;
    private VideoView videoview;
    private FrameLayout.LayoutParams layoutParams;
    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
        frame = (FrameLayout) findViewById(R.id.frame);
        text = (TextView) findViewById(R.id.text_field_1);
        videoview = (VideoView) findViewById(R.id.video_view);
        resetDisplay();
        getWindow().setFormat(PixelFormat.UNKNOWN);
        videoview.setOnPreparedListener(new OnPreparedListener(){
            @Override
            public void onPrepared(MediaPlayer mp){
                mp.setLooping(true);
            }
        });
        video = Uri.parse(Environment.getExternalStorageDirectory()+"/video.avi");
        videoview.setZOrderOnTop(false);
        videoview.setVideoURI(video);
        videoview.start();
        text.bringToFront();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {}
    }
    protected void onPause(){
        super.onPause();
        videoview.suspend();
        wl.release();
    }
    protected void onResume(){
        super.onResume();
        resetDisplay();
        videoview.start();
        wl.acquire();
    }
    private void resetDisplay()
    {
        frame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | 
                View.SYSTEM_UI_FLAG_FULLSCREEN |
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                View.SYSTEM_UI_FLAG_LOW_PROFILE);
    }
}

和我的布局XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clipChildren="false"
    android:id="@+id/frame"
    tools:context="com.example.exampleapp.MainActivity" >
    <VideoView
        android:id="@+id/video_view"
        android:clickable="false"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fitsSystemWindows="true"        
        />
    <TextView
        android:id="@+id/text_field_1"
        android:textColor="#FFFFFF"
        android:textSize="25sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</FrameLayout>

有人知道如何强制文本以沉浸式模式出现在视频顶部吗?

谢谢!

尝试设置

android:layout_gravity

TextView的属性。

例如

android:layout_gravity="center" 

android:layout_gravity="bottom|center_horizontal"

如何让textview居中于ImageView的顶部

如何在我的情况下以编程方式显示另一个布局的顶部?

把View放到Android的VideoView上

最新更新