0

ビデオの再生と 2 つの ImageButtons をすべて同じ画面に表示するビューを作成しようとしています。VideoView を使用して、両方のボタンにビデオと ImageButtons を含めています。各機能を個別にテストすると両方とも正しく表示されますが、同じ画面に両方を表示しようとすると同時に表示されません! VideoView をより小さな layout_width と layout_height に制限して、多くのレイアウト (フレーム、線形、相対) を試し、xml ファイルで重みを試しましたが、何も機能していないようです。これを表示するのは簡単すぎてカスタム ビューが必要ないように思えますが、必要に応じて表示します。

ここに私の質問があります: imageButtons と VideoView を同じ画面に表示する方法を知っていますか? カスタム ビューを作成するときに、VideoView や ImageButton などの Android ビューを使用できますか? それとも、カスタム ビューのキャンバスに 2D のものを描画できますか?

参照としての私のコードは次のとおりです: XML

<LinearLayout
        android:id="@+id/videopart"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:layout_weight="1">
     <VideoView
         android:id="@+id/videoplayer"
         android:layout_width="395dp"
         android:layout_height="111dp" >
       </VideoView>
</LinearLayout>

 <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_weight="1">   

        <ImageButton
             android:contentDescription="@string/top"
             android:id="@+id/topbutton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"                
             android:paddingRight="5dip" 
             android:src="@drawable/yesbutton"
             android:background="@null"/>  
       <ImageButton
             android:contentDescription="@string/bottom"
             android:id="@+id/bottombutton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"  
             android:paddingLeft="5dip" 
             android:src="@drawable/nobutton"
             android:background="@null">
        </ImageButton>           

    </LinearLayout>

そして活動:

public class iplayer extends Activity {
VideoView videoHolder;
MediaPlayer mp;
ImageButton top, bottom;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);      

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    videoHolder = new VideoView(this);

    //if you want the controls to appear
    videoHolder.setMediaController(new MediaController(this));

    Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.interactivevid); 
    videoHolder.setVideoURI(video);

    // video finish listener:
    videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            // The video has finished, return from this activity
            finish(); //close activity
        }
    });

    videoHolder.requestFocus();
    /*
    videoHolder.requestLayout();
    videoHolder.invalidate();
    videoHolder.getLayoutParams().width = 20;//480;     
     */
    //start video
    drawButtons();
    //videoHolder.setPadding(BIND_NOT_FOREGROUND, BIND_NOT_FOREGROUND, BIND_NOT_FOREGROUND, BIND_NOT_FOREGROUND);
    videoHolder.setPadding(5, 0, 5, 200);
    setContentView(videoHolder); // used to actually put in video. when removed, shows buttons 
    videoHolder.start();    

 }


private void drawButtons(){

    //make buttons invisible
    top = (ImageButton)findViewById(R.id.topbutton);
    top.setImageResource(R.drawable.yesbutton);
    top.setVisibility(View.VISIBLE);

    bottom = (ImageButton)findViewById(R.id.bottombutton);
    bottom.setImageResource(R.drawable.nobutton); 
    bottom.setVisibility(View.VISIBLE);
}
}
4

1 に答える 1

0

私は今これをテストできるコンピューターではありませんが、試してみたいのは絶対レイアウトです。

ビデオの上にボタンを配置できるはずです。ここに例があり ます http://www.tutorialforandroid.com/2009/01/absolutelayout-in-android-xml.html

ボタンと VideoView を同じレイアウトに配置することもできます。

于 2012-04-07T19:02:55.110 に答える