TextViews无法显示与沉浸模式VideoView的顶部启用(Android版) [英] TextViews aren't showing up on top of VideoView with Immersive Mode enabled (Android)
问题描述
我开发一个应用程序,将显示一个视频作为背景,并有文字和在它上面的其他视图(使用的FrameLayout)。
由于某些原因,当身临其境的模式下启用,我使用的测试TextView的消失,虽然它刷到显示系统导航/状态栏何时重新出现。
下面是我的code:
公共类MainActivity延伸活动{ 私人乌里视频;
私人PowerManager.WakeLock WL;
私人的FrameLayout框架;
私人TextView的文本;
私人VideoView videoview;
私人FrameLayout.LayoutParams的LayoutParams; @燮pressWarnings(德precation)
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 的setContentView(R.layout.activity_main);
电源管理PM =(电源管理)getSystemService(Context.POWER_SERVICE);
WL = pm.newWakeLock(PowerManager.FULL_WAKE_LOCKDoNotDimScreen); 帧=(的FrameLayout)findViewById(R.id.frame);
文字=(TextView的)findViewById(R.id.text_field_1);
videoview =(VideoView)findViewById(R.id.video_view); resetDisplay();
。getWindow()和setFormat(PixelFormat.UNKNOWN); videoview.setOn preparedListener(新在preparedListener(){
@覆盖
在prepared(MediaPlayer的MP)公共无效{
mp.setLooping(真);
}
}); 视频= Uri.parse(Environment.getExternalStorageDirectory()+/ video.avi);
videoview.setZOrderOnTop(假);
videoview.setVideoURI(视频)
videoview.start();
text.bringToFront(); }
@覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
//充气菜单;如果是present这增加了项目操作栏。
。getMenuInflater()膨胀(R.menu.main,菜单);
返回true;
} @覆盖
公共布尔onOptionsItemSelected(菜单项项){
//处理动作栏项目点击这里。操作栏会
//自动处理上点击主页/向上按钮,只要
//你在AndroidManifest.xml中指定一个父活动。
INT ID = item.getItemId();
如果(ID == R.id.action_settings){
返回true;
}
返回super.onOptionsItemSelected(项目);
} @覆盖
公共无效onWindowFocusChanged(布尔hasFocus){
super.onWindowFocusChanged(hasFocus);
如果(hasFocus){} } 保护无效的onPause(){
super.onPause();
videoview.suspend();
wl.release();
} 保护无效onResume(){
super.onResume();
resetDisplay();
videoview.start();
wl.acquire();
} 私人无效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:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:clipChildren =假
机器人:ID =@ + ID /帧
工具:上下文=com.example.exampleapp.MainActivity> < VideoView
机器人:ID =@ + ID / VIDEO_VIEW
机器人:可点击=假
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:fitsSystemWindows =真
/> <的TextView
机器人:ID =@ + ID / text_field_1
机器人:文字颜色=#FFFFFF
机器人:TEXTSIZE =25sp
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/参考hello world/>
< /&的FrameLayout GT;
有谁知道如何强制文本出现在沉浸式模式的视频顶部?
谢谢!
尝试设置了
的android:layout_gravity
您的TextView的属性。
例如
的android:layout_gravity =中心
或
的android:layout_gravity =底部| CENTER_HORIZONTAL
<一个href=\"http://stackoverflow.com/questions/17752811/how-to-get-a-textview-centred-on-top-of-an-imageview\">How得到集中在一个ImageView的上面一个TextView
<一个href=\"http://stackoverflow.com/questions/6690530/how-to-show-one-layout-on-top-of-the-other-programmatically-in-my-case\">How显示在另一个的上面的一个布局编程在我的情况?
把任何观对在Android中 <一个VideoView / p>
I am developing an app that will display a video as a "backdrop" and have text and other views on top of it (using a FrameLayout).
For some reason, when immersive mode enabled, the textview I am using to test disappears, though it does reappear when swiping to show the system nav/status bars.
Here is my code:
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);
}
}
And my layout 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>
Does anyone know how to force the text to appear in immersive mode on top of the video?
Thanks!
Try setting the
android:layout_gravity
property of your TextView.
For example
android:layout_gravity="center"
or
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?
Put any View over a VideoView in Android
这篇关于TextViews无法显示与沉浸模式VideoView的顶部启用(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!