2012-11-09 40 views
0

我展示的videoview視頻:安卓視頻綿延上方向變化

在我的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秒之後,視頻延伸至全屏。 (它不保持縱橫比,它延伸的高度)

像這樣:

enter image description here

回答

0

我結束了子類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) {..} 

我手動設置縱向或橫向的尺寸,具體取決於用戶設備的方向。