我正在开发一个应用程序,将视频显示为"背景"并在其上面放置文本和其他视图(使用FrameLayout)。
出于某种原因,当启用沉浸式模式时,我用于测试的文本视图会消失,但是在滑动以显示系统导航/状态栏时它会重新出现。
这是我的代码:
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>
有谁知道如何强制文字在视频顶部以沉浸式模式显示?
谢谢!
答案 0 :(得分:0)
尝试设置
android:layout_gravity
TextView的属性。
例如
android:layout_gravity="center"
或
android:layout_gravity="bottom|center_horizontal"
How to get a textview centred on top of an ImageView
How to show one layout on top of the other programmatically in my case?