No links clickable in WebView embedded in ViewGroup if other children there
I have a RelativeLayout
that contains a WebView
and a ListView
(ListViewContainer is a subclass of ListView:
public AdListViewContainer(Context context, ServiceLookup lookup, MarketList list, Registry registry, BitmapCache bitmapCache, Utilities utilities, ActionF开发者_如何学Pythonlipper flipper) {
super(context);
mScale = getContext().getResources().getDisplayMetrics().density;
final int orientation = getResources().getConfiguration().orientation;
setClickable(true);
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
mAd = new WebView(context);
mAd.setId(1234);
mAd.setWebViewClient(new AdListWebClient());
mAd.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d (TAG, "Inner Event " + event.getAction());
return false;
}
});
mAd.getSettings().setJavaScriptEnabled(true);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
lp.addRule(ALIGN_PARENT_BOTTOM, 1);
addView(mAd, lp);
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
if (mAd != null) {
lp.addRule(ALIGN_BOTTOM, mAd.getId());
}
mListContainer = new ListViewContainer(context, lookup, list, registry, bitmapCache, utilities, flipper);
addView(mListContainer, lp);
}
The WebView is showing an ad generated by Adition, basically an img-tag in an a-tag.
The problem I have is that the ad can't be clicked. No touch or click events are received by the WebView. When I remove the ListView and the WebView is the only child of the ViewGroup (by removing the last addView call), the ad is clickable and everything is fine.
ListViewContainer
is a straightforward subclass of ListView
that contains a load of clickable LinearLayouts.
Any help appreciated!
Ok, I found the issue. The ListView was overlapping the WebView, caused by using ALIGN_BOTTOM instead of ABOVE. D'Oh. HierarchyViewer was a blast in finding this.
I overrode OnTouchEvent for the Webview, and put the WebView inside of a FrameLayout, filling it, then put everything else I needed on top of the webview. Working great!
精彩评论