使用videoview Android视频没有采取全屏横向模式 [英] video not taking full screen in landscape mode using videoview android

查看:321
本文介绍了使用videoview Android视频没有采取全屏横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I M使用在纵向模式下videoview,并设置该清单中

i m using videoview in portrait mode and have set this in manifest

<activity android:name="com.ui.VideoDetailActivity" android:configChanges="orientation|screenSize|keyboard"   android:theme="@style/newtheme"
            />

我的布局工作在纵向模式很好,​​但在景观我不希望加载从布局土地另一个布局,因为这将开始从起始位置的视频缓冲,因此我尝试透过程式设计改变观点,但预期这不工作.Layout肖像:

my layout is working fine in portrait mode but in landscape i do not want to load another layout from layout-land because this will start buffering of video from start position so i m trying to change views programtically but this is not working as expected.Layout for portrait :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">
   <RelativeLayout
       android:id="@+id/rlayout_detailvideo"
       android:layout_width="match_parent"
       android:layout_height="250dp"
       android:visibility="visible"
       android:background="#000000">
    <com.controls.VideoViewCustom android:id="@+id/videoplayer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
       <ImageView
           android:id="@+id/imageview_videodetailbackarrow"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:src="@drawable/video_detail_back_btn"
           android:padding="15dp"
           android:layout_alignParentLeft="true"
           android:layout_marginLeft="@dimen/videodetail_backarrow_marginleft"
           android:layout_marginTop="@dimen/videodetail_backarrow_margintop"/>
       <ImageView
           android:id="@+id/imageview_edit"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:src="@drawable/video_detail_edit_btn"
           android:padding="15dp"
           android:layout_alignParentRight="true"
           android:layout_marginRight="@dimen/videodetail_edit_marginright"
           android:layout_marginTop="@dimen/videodetail_backarrow_margintop"/>
       <ImageView
           android:id="@+id/imageview_bottom"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:src="@drawable/video_detail_fullscreen_btn"
           android:padding="15dp"
           android:layout_alignParentBottom="true"
           android:layout_alignParentRight="true"
           android:layout_marginRight="@dimen/videodetail_edit_marginright"
           android:layout_marginTop="@dimen/videodetail_backarrow_margintop"/>
       <LinearLayout
           android:id="@+id/layout_videocontrols"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical"
           android:layout_alignParentBottom="true"
           android:background="#000000">
           <SeekBar
               android:id="@+id/seekbar_video"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:layout_alignParentLeft="true"
               android:layout_centerVertical="true"
               android:progressDrawable="@drawable/seek_bar"
               android:thumb="@drawable/thumb"
               android:layout_margin="3dp"
               android:minHeight="5dip"
               android:maxHeight="8dip"
               android:progress="0"
               android:indeterminate="false"/>
           <LinearLayout
               android:layout_width="match_parent"
               android:layout_height="@dimen/videodetail_videocontrol_height"
               android:orientation="horizontal">

               <ImageView
                   android:id="@+id/imageview_playpause"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:src="@drawable/video_detail_play_btn"
                   android:layout_gravity="center_vertical"
                   android:layout_marginRight="@dimen/videodetail_edit_marginright"
                   android:padding="5dp"
                   android:layout_marginLeft="10dp"
                   />
               <TextView
                   android:id="@+id/textview_videoduration"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:text="00:00"
                   android:layout_gravity="center_vertical"
                   android:textSize="@dimen/videodetail_textview_videoduration_fontsize"
                   android:textColor="@color/white"/>

           </LinearLayout>
       </LinearLayout>

   </RelativeLayout>

   <!-- <android.support.design.widget.TabLayout
        android:id="@+id/videodetail_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/actionbar_backgroundcolor"
        app:tabIndicatorHeight="3dp"
        android:layout_below="@+id/rlayout_detailvideo"
        android:background="#ffffff"
        />-->
    <android.support.design.widget.TabLayout
        android:id="@+id/videodetail_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorColor="@color/actionbar_backgroundcolor"
        app:tabIndicatorHeight="3dp"
        app:tabGravity="fill"
        android:layout_below="@+id/rlayout_detailvideo"
        android:background="#ffffff"/>
    <View
        android:id="@+id/view_videodetail"
        android:layout_height="0.3dp"
        android:layout_width="match_parent"
        android:background="@android:color/darker_gray"
        android:layout_below="@+id/videodetail_tabs"
        />
    <android.support.v4.view.ViewPager
        android:id="@+id/videodetail_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_below="@+id/view_videodetail"
        android:background="@color/white"
        android:layout_marginTop="@dimen/infotab_layout_margintop"
        />
</RelativeLayout>

在景观我想告诉videoview为全屏幕上videoview,一切都应该被隐藏的顶部搜索栏的布局,但这是行不通的。

in landscape i want to show videoview as full screen with seekbar layout on top of videoview and everything should be hidden but this is not working.

  @Override
 public void onConfigurationChanged(Configuration newConfig)
 {
     super.onConfigurationChanged(newConfig);
     if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) //To fullscreen
     {
         tabsVideoDetail.setVisibility(View.GONE);
         pagerVideoDetail.setVisibility(View.GONE);
         view.setVisibility(View.GONE);
         seekBarLayout.setVisibility(View.GONE);


         DisplayMetrics metrics = new DisplayMetrics();
         getWindowManager().getDefaultDisplay().getMetrics(metrics);
         android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) videoView.getLayoutParams();
         params.width =  metrics.widthPixels;
         params.height = metrics.heightPixels;
         params.leftMargin = 0;
         videoView.setLayoutParams(params);

     }
     else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
     {
         tabsVideoDetail.setVisibility(View.VISIBLE);
         pagerVideoDetail.setVisibility(View.VISIBLE);
         view.setVisibility(View.VISIBLE);
         seekBarLayout.setVisibility(View.VISIBLE);
         DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
         android.widget.LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) videoView.getLayoutParams();
         params.width =  metrics.widthPixels;
         params.height = (int) (250*metrics.density);
         videoView.setLayoutParams(params);
     }
}
this is producing this layout  while seekbar layout should stay on bottom everytime


在景观我去每个视图,并给红色背景这表明它不是充分的高度如何避免这个问题?

in landscape i gone every view and give red background this indicates that its not taking full height how to avoid this problem ?

推荐答案

这是为时已晚,但以供将来参考:

It's too late but for future Reference :

1添加以下内容的Manifest.xml:

1- Add following to Manifest.xml :

android:configChanges="orientation|keyboardHidden|screenSize"

2-在你活动覆盖onConfiguration改变为如下:

2- In you Activity Override onConfiguration changed as follow :

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (null == emVideoView) return;
        if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().getDecorView().invalidate();
            float height = getWidthInPx(this);
            float width = getHeightInPx(this);
            emVideoView.getLayoutParams().height = (int) width;
            emVideoView.getLayoutParams().width = (int) height;
        } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            final WindowManager.LayoutParams attrs = getWindow().getAttributes();
            attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().setAttributes(attrs);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            float width = getWidthInPx(this);
            float height = dip2px(this, 200.f);
            emVideoView.getLayoutParams().height = (int) height;
            emVideoView.getLayoutParams().width = (int) width;
        }
    }

3把这些功能的地方:

3- Put these function someWhere :

public static final float getHeightInPx(Context context) {
        final float height = context.getResources().getDisplayMetrics().heightPixels;
        return height;
    }

    public static final float getWidthInPx(Context context) {
        final float width = context.getResources().getDisplayMetrics().widthPixels;
        return width;
    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

这篇关于使用videoview Android视频没有采取全屏横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆