2016-09-01 7 views
0

私は、レイアウトを50%の垂直マークまでスライドさせてループさせてビデオをストリーミングするアプリケーションを書いています。私はまた、50-60%程度の透明度を持つレイアウトの背景を白にしたい。私はすでにビデオをループする方法を見つけました。私は別のアクティビティで必要なレイアウトを持っています。アニメーションをスライドさせて&まで下げました。私のXMLファイルレイアウトをレイアウトリストにマップする方法と、上にスライドして、OnClick-sなどの内部イベントを処理する方法。レイアウトのスライドアップで動画を再生

MainActivity:

public class MainActivity extends Activity{ 


    private VideoView myVideoView; 
    private MediaController mediaControls=null; 
    private int position = 0; 
    private String ppm_val=null; 
    private TextView distance; 
    private AdkReadTask mAdkReadTask; 
    private int myInt = -10; 
    private TextView tv; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     View decorView = getWindow().getDecorView(); 
     int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE 
       | View.SYSTEM_UI_FLAG_FULLSCREEN; 
     decorView.setSystemUiVisibility(uiOptions); 
     buttonLED = (ToggleButton) findViewById(R.id.toggleButtonLed); 
     distance = (TextView) findViewById(R.id.textViewIntro); 
     buttonLED.setVisibility(View.INVISIBLE); 
     tv = (TextView) findViewById(R.id.ppm); 


     Animation slide_down = AnimationUtils.loadAnimation(getApplicationContext(), 
       R.anim.slide_down); 

     final Animation slide_up = AnimationUtils.loadAnimation(getApplicationContext(), 
       R.anim.slide_up); 



     myVideoView = (VideoView) findViewById(R.id.videoView); 
     Display display = getWindowManager().getDefaultDisplay(); 
     Point size = new Point(); 
     display.getSize(size); 
     myVideoView.getHolder().setFixedSize(size.x, size.y); 
     tv.setText(""+size.x+":"+size.y); 

     try { 
      //set the uri of the video to be played 
      myVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.test758)); 

     } catch (Exception e) { 
//   Log.e("Error", e.getMessage()); 
//   e.printStackTrace(); 
     } 

     //we also set an setOnPreparedListener in order to know when the video file is ready for playback 
     myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 

      public void onPrepared(MediaPlayer mediaPlayer) { 

       mediaPlayer.setLooping(true); 
       myVideoView.seekTo(position); 
       if (position == 0) { 
        myVideoView.start(); 
       } else { 
        //if we come from a resumed activity, video playback will be paused 
        myVideoView.pause(); 
       } 
      } 
     }); 

     if (((MyApplication) this.getApplication()).checkNull()) { 
      ((MyApplication) this.getApplication()).init(this); 
      ((MyApplication) this.getApplication()).open(); 

     } 

     if (mAdkReadTask==null) { 
      mAdkReadTask = new AdkReadTask(); 
      mAdkReadTask.execute(); 
     } 
    } 



    @Override 
    public void onResume() { 
     super.onResume(); 
     ((MyApplication) this.getApplication()).write("1"); 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
    } 


    public String output=""; 
    String[] sarr = new String[3]; 
    /* 
    * We put the readSerial() method in an AsyncTask to run the 
    * continuous read task out of the UI main thread 
    */ 
    private class AdkReadTask extends AsyncTask<Void, String, String> { 

     private boolean running = true; 

     public void pause(){ 
      running = false; 
     } 
     public void start(){ 
      running = true; 
     } 
     private int cnt = 0; 
     @Override 
     protected String doInBackground(Void... params) { 

      while(running) { 


       if (this.isCancelled()) 
        break; 

       String s = ((MyApplication) getApplication()).read(); 
       if (s.charAt(0)=='R'){ 
        running = false; 
       } 
       cnt++; 
       publishProgress(s); 
      } 

      return output; 
     } 

     @Override 
     protected void onProgressUpdate(String... progress) { 
      if(progress[0].charAt(0)=='P') { 
       tv.setText("Air quality: " + progress[0].substring(1, progress[0].length())); 
       ppm_val = progress[0].substring(1, progress[0].length()); 
       ((MyApplication) getApplication()).setPPM(ppm_val); 
      } 
     } 
     @Override 
     protected void onPostExecute(String result){ 
      next(); 
     } 
    } 

    private void next() { 
     final Intent intent = new Intent(this, BuyRecycleActivity.class); 
     new android.os.Handler().postDelayed(
       new Runnable() { 
        public void run() { 
         startActivity(intent); 
        } 
       }, 
       1000); 
    } 

} 

slide_up.xml:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <translate 
     android:duration="1000" 
     android:fromYDelta="100%" 
     android:toYDelta="0" /> 
</set> 

slide_down.xml:

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" > 

    <translate 
     android:duration="1000" 
     android:fromYDelta="0" 
     android:toYDelta="100%" /> 
</set> 

EDIT 1: コードが追加されました。私が必要とするのは、BuyRecycleActivityのレイアウトをビデオの再生中にメインアクティビティの一番下にスライドさせる方法です。

+0

ここにコードを入力してください –

答えて

0

includeのレイアウトで解決しました。その後、デフォルトでは非表示に設定します。

関連する問題