我正在编写一个应用程序,我想循环播放视频,布局滑动到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>
编辑1: 代码已添加。我只需要将BuyRecycleActivity的布局从50%的主要活动底部向上滑动,同时视频仍在播放
答案 0 :(得分:0)
使用include
布局解决。然后默认设置它们不可见。