【问题标题】:Android: Video stretches on orientation changeAndroid:视频在方向变化时拉伸
【发布时间】:2012-11-09 12:28:13
【问题描述】:

我正在视频视图中显示视频:

在我的 XML 中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:gravity="center"
  android:layout_height="fill_parent">

    <VideoView
    android:layout_gravity="center"
    android:id="@+id/videoview_player"
    android:layout_width="wrap_content"
     android:layout_height="wrap_content" />

</LinearLayout>

看起来这很完美。视频会自行调整大小以填满屏幕,而视频仍保持其纵横比。

但在平板电脑上,在纵向大约 30 到 60 秒后,视频会拉伸到全屏。 (它不保持纵横比,它拉伸了高度)

像这样:

【问题讨论】:

    标签: android orientation android-videoview


    【解决方案1】:

    我最终继承了 VideoView:

    public class PlayerVideoView extends VideoView{
    
        private int mForceHeight = 0;
        private int mForceWidth = 0;
        public PlayerVideoView(Context context) {
            super(context);
        }
    
        public PlayerVideoView(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }
    
        public PlayerVideoView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        public void setDimensions(int w, int h) {
            this.mForceHeight = h;
            this.mForceWidth = w;
    
        }
    
        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            setMeasuredDimension(mForceWidth, mForceHeight);
        }
    }
    

    我在 onCreate 中设置尺寸的位置

    videoView.setDimensions(800, 600);
    

    然后在

    @Override
    public void onConfigurationChanged(Configuration newConfig) {..}
    

    我根据用户的设备方向手动设置纵向或横向尺寸。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-31
      相关资源
      最近更新 更多