2012-05-17 65 views
15

我目前正在嘗試實現一個視頻視圖,該視頻視頻將在特定位置上顯示視頻。我可以顯示沒有問題的全屏視頻。然而,無論何時我試圖在一幀內顯示視頻(例如一個小矩形),我只能在該視圖中顯示一部分視頻。我無法將視頻融入該觀點。如何在某個特定位置查看視頻內的視頻?

我已經找了很多關於在an​​droid中縮放視頻的鏈接,但我找不到任何方法來做到這一點。任何有關該問題的幫助都將有所幫助。

我正在使用的是我有2個不同的類。其中之一是我的視頻活動類等一個是一個輔助類:

public class VideoViewCustom extends VideoView { 
    private int mForceHeight = 0; 
    private int mForceWidth = 0; 
    public VideoViewCustom(Context context) { 
     super(context); 
    }  
    public VideoViewCustom(Context context, AttributeSet attrs) { 
     this(context, attrs, 0); 
    } 

    public VideoViewCustom(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) { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
     setMeasuredDimension(mForceWidth, mForceHeight); 
    } 
} 

該類幫我正確設置videoview的尺寸,但我不能讓視頻配合進該區域。我的意思是我無法調整視頻以適合該地區。我不知道是否Android是自動縮放到給定的尺寸,但我無法做到這一點。

+0

http://stackoverflow.com/questions/4434027/android-videoview-orientation-change-with-buffered-video 你 –

+0

我已經去了,但它沒有什麼區別此鏈接可能是有用的。不知道爲什麼艱難 – denizt

+2

好吧,我解決了這個問題,將我的應用程序移植到ICS。在ICS中,它沒有問題。但是當我試圖用Froyo來做這件事時,我遇到了很多問題。如果有人也面臨着他們,我會過去他們。 – denizt

回答

2

也許這將幫助你......

public void onMeasure(int width, int height) 
{ 
    getHolder().setFixedSize(width, height); 
    forceLayout(); 
      setMeasuredDimension(width, height); 
    invalidate(); 
} 

...和嘗試的RelativeLayout

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

    <VideoView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentLeft="true"/> 

</RelativeLayout> 
1

我認爲你必須創建一個ViewGroup中,你可以實現onLayout()方法。

在這裏,您可以設置視圖的位置,直接調用它們中的每一個的layout()方法。

例子:

ViewGroup vg = new ViewGroup(this) { 

    @Override 
    protected void onLayout(boolean changed, int l, int t, int r, int b) { 
      int x = getMeasuredWidth(); 
      int y = getMeasuredHeight(); 
      for (int i = 0; i < vg.getChildCount(); i++) { 
       if(vg.getChildAt(i) instanceof TextView){ 
        vg.getChildAt(i).layout(...);//and so on... 

       } 
      } 
     } 
}; 

希望幫助!