您好我一直在研究这个问题。我正在使用GestureListener和ViewFlipper在两个不同的WebView之间滑动。一个webview是聊天,另一个是flash流。蒸汽是全屏的,当我滑动时它不会离开屏幕。聊天滑动但是当我向后滑动时它不会返回。当我改变方向时,我可以看到下面的聊天。请帮忙。
手势正常,但视频无法移动。我怎么能把它移到后面?
public class WebViewPager extends Activity implements SimpleGestureListener {
private FrameLayout holder;
private WebView streamView;
private WebView chatView;
private ViewFlipper flipView;
private ProgressDialog pDialog;
private String url = "http://www.justin.tv/dbz_hd2/popout";
private String url2 = "http://www.justin.tv/chat/embed?channel=dbz_hd2";
private SimpleGestureFilter filter;
private Animation slideLeft;
private Animation slideRight;
final Activity activity = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
holder = (FrameLayout) findViewById(R.id.streamViewHolder);
streamView = (WebView) findViewById(R.id.streamView);
StreamClientSettings();
flipView = (ViewFlipper) findViewById(R.id.mainFlipper);
flipView.setDisplayedChild(1);
this.filter = new SimpleGestureFilter(this, this);
this.filter.setMode(SimpleGestureFilter.MODE_TRANSPARENT);
slideLeft = AnimationUtils.loadAnimation(this, R.anim.translate);
slideRight = AnimationUtils.loadAnimation(this, R.anim.translate);
new ManageViews().execute();
}
private class ManageViews extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... args) {
// TODO Auto-generated method stub
chatView = (WebView) findViewById(R.id.chatView);
ChatClientSettings();
return null;
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent me) {
this.filter.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}
public void StreamClientSettings() {
// streamView = new WebView(this);
// streamView.setLayoutParams(new ViewGroup.LayoutParams(
// LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
streamView.getSettings().setPluginState(PluginState.ON);
streamView.getSettings().setJavaScriptEnabled(true);
streamView.setWebViewClient(new StreamClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView v, String url) {
return false;
}
});
streamView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
streamView.getSettings().setLoadsImagesAutomatically(true);
streamView.getSettings().setUseWideViewPort(true);
streamView.getSettings().setLoadWithOverviewMode(true);
String s = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0.1)";
streamView.getSettings().setUserAgentString(s);
// streamView.requestFocus(View.FOCUS_DOWN);
streamView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
// switch (event.getAction()) {
// case MotionEvent.ACTION_DOWN:
// case MotionEvent.ACTION_UP:
// if (!v.hasFocus()) {
// v.requestFocus();
// }
// break;
// }
return false;
}
});
streamView.loadUrl(url);
}
public void ChatClientSettings() {
//chatView = new WebView(this);
// chatView.setLayoutParams(new ViewGroup.LayoutParams(
// LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
chatView.getSettings().setPluginState(PluginState.ON);
chatView.getSettings().setJavaScriptEnabled(true);
chatView.setWebViewClient(new StreamClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView v, String url) {
return false;
}
});
chatView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
chatView.getSettings().setLoadsImagesAutomatically(true);
chatView.getSettings().setUseWideViewPort(true);
chatView.getSettings().setLoadWithOverviewMode(true);
String s = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0.1)";
chatView.getSettings().setUserAgentString(s);
chatView.requestFocus(View.FOCUS_DOWN);
chatView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
});
chatView.loadUrl(url2);
}
private void setStreamView() {
if (flipView.getDisplayedChild() != 0) {
flipView.setDisplayedChild(0);
flipView.setInAnimation(slideRight);
//flipView.setOutAnimation(slideLeft);
}
}
private void setChatView() {
if (flipView.getDisplayedChild() != 1) {
flipView.setDisplayedChild(1);
flipView.setInAnimation(slideLeft);
//flipView.setOutAnimation(slideRight);
}
}
@Override
public void onSwipe(int direction) {
// TODO Auto-generated method stub
switch (direction) {
case SimpleGestureFilter.SWIPE_RIGHT:
if (flipView.getDisplayedChild() == 0) {
//flipView.setDisplayedChild(1);
setChatView();
}
break;
case SimpleGestureFilter.SWIPE_LEFT:
if (flipView.getDisplayedChild() == 1) {
//flipView.setDisplayedChild(0);
setStreamView();
}
break;
}
}
我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ViewFlipper
android:id="@+id/mainFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/streamViewHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null" >
<WebView
android:id="@+id/streamView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chatView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ViewFlipper>
</LinearLayout>
答案 0 :(得分:1)
事实证明,Flash视频播放器是某种无法由java控制的父级。通过从布局持有者中移除视图,可以实现滑动的效果。经过了大量的试验和错误,但它确实有效!
@Override
public void onSwipe(int direction) {
// TODO Auto-generated method stub
switch (direction) {
case SimpleGestureFilter.SWIPE_RIGHT:
if (flipView.getDisplayedChild() == 1) {
//flipView.setDisplayedChild(1);
setStreamView();
holder.addView(streamView);
}
break;
case SimpleGestureFilter.SWIPE_LEFT:
if (flipView.getDisplayedChild() == 0) {
//flipView.setDisplayedChild(0);
setChatView();
holder.removeAllViews();
}
break;
}