Я пытаюсь создать набор веб-представлений с горизонтальной прокруткой, используя виджет Галерея. Проблема в том, что я не могу пролистывать просмотры, что, конечно, работает для галерей изображений. Following cookbook code, in the activity's onCreate() I:
g = (Gallery) findViewById(R.id.chapter_browser);
g.setAdapter(new WebViewAdapter(this));
Then the adapter creates the webviews and returns them for the requested indices:
public class WebViewAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private String[] pages = {
"test1.html",
"test2.html",
"test3.html",
"test4.html"
};
public WebViewAdapter(Context c) {
mContext = c;
}
public int getCount() {
return pages.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
WebView i = new WebView(mContext);
i.loadUrl("file:///android_asset/" + pages[position]);
i.setBackgroundResource(mGalleryItemBackground);
i.setWebViewClient(new WebViewClient());
i.setLayoutParams(new Gallery.LayoutParams(100,100));
i.setInitialScale(100);
i.setFocusable(false);
i.setClickable(false);
return i;
}
}
The problem seems to be that the WebView insists on consuming touch events, despite setting its clickable
attribute off. I tried creating an OnTouchEventListener for the views and then dispatching then events to the gallery, but that just seems to crash the program.
Any clues appreciated.