こんにちは、私はしばらくこれに取り組んできました。GestureListener と ViewFlipper を使用して、2 つの異なる WebView 間をスワイプしています。1 つの Web ビューはチャットで、もう 1 つはフラッシュ ストリームです。スチームは全画面表示で、スワイプしても画面から消えません。チャットはスワイプしますが、スワイプバックしても元に戻りません。向きを変えると、下にチャットが表示されます。助けてください。
ジェスチャーは機能していますが、ビデオは動きません。どうすれば後ろに移動できますか?
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>