2013-04-24 63 views
10

私はビデオビューを埋めるためにビデオを伸ばそうとします。ターゲットは、最初の写真のようにデバイス内に表示されるビューを作成することです(レイアウトプレビューで見るようなもの)。VideoView、ビデオビューのアスペクト比を塗りつぶすためのストレッチ

この質問に対する回答の多くはthis linkです。

私はこれを試しましたが、私はまだビデオの表示を埋めることはできませんでした。

この私のレイアウトコード:

enter image description here

しかし、デバイス上の結果が異なっている:

enter image description hereここ

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/search_gren_screen"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/go_back" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:onClick="onclick" 
      android:text="Try again" /> 

     <Button 
      android:id="@+id/back_to_pick_song" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Select another song" 
      android:onClick="onclick" /> 

     <Button 
      android:id="@+id/btn_continue" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:onClick="onclick" 
      android:text="Amazing, continue!" /> 
    </LinearLayout> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    <VideoView 
     android:id="@+id/videoView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_gravity="center" /> 
    </FrameLayout> 
</LinearLayout> 

あなたは私の宣言レイアウトのプレビューを持っています

+0

あなたの必要性を満たすためにあなたのレイアウトコードは大丈夫です。しかし、 'VideoView'はその中で再生されているビデオに関して縮小/伸縮することに注意してください。 –

+0

okですので、mMediaRecorder.setVideoSize(640、480)を追加するには、メディアレコーダーの縦横比を変更する必要があります。私はこれを試してit'n仕事... ??? – idan

+0

この回答を確認してくださいhttp://stackoverflow.com/a/38971707/1153703 –

答えて

25

あなたの外部レイアウトを相対レイアウトにし、VideoViewをその内部に配置してみてください。以下のような

何か:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/trim_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
      android:id="@+id/buttonContainer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 

    <Button 
      android:id="@+id/go_back" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:onClick="onclick" 
      android:text="Try again" /> 

    <Button 
      android:id="@+id/back_to_pick_song" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Select another song" 
      android:onClick="onclick" /> 

    <Button 
      android:id="@+id/btn_continue" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:onClick="onclick" 
      android:text="Amazing, continue!" /> 
    </LinearLayout> 

    <VideoView 
    android:id="@+id/VideoView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:layout_below="@id/buttonContainer"/> 
</RelativeLayout> 
+0

ありがとうございました.... – idan

+0

素晴らしいです。それは働く.. – Neela

+0

それはfuc..ing workssss !!これは、このことを達成する最も簡単な方法です。私はこれを達成しようと多くの時間を無駄にしてきました。どうもありがとう!!!!!! – KinGPinG

5

は別のsolutionを見つけました。それは習慣を必要としませんVideoView

関連する問題