我有一个包含文章列表的 ListView。每 X 篇文章(目前 10 篇),我都有一个显示广告的 WebView。我可以单击任何列表项,除了显示 WebView 的项正上方的项。那个不会注册我的点击。
显示或隐藏 WebView 的代码:
if(position % 10 == 0) // || position == 0) && position > 0
{
viewHolder.adView.loadUrl(tmpAdURL);
viewHolder.adView.setVisibility(View.VISIBLE);
}
else
{
viewHolder.adView.setVisibility(View.GONE);
viewHolder.adView.invalidate();
}
主要的.xml
<ListView android:id="@+id/articles_list"
style="@style/ListView"
android:fadingEdge="vertical"
android:fadingEdgeLength="16dp"
android:divider="@color/extreme_light_gray"
android:dividerHeight="1dp" />
MainActivty.java 的 onCreate() 中的监听器:
articleEntryListView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Log.d("MINE", "ARTICLE CLICKED");
}
}
article_entry_list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="60dp" >
<!-- Title of the news entry -->
<ImageView
android:id="@+id/article_thumbnail"
android:layout_width="90dp"
android:layout_height="80dp"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"
android:contentDescription="@string/articleThumbnail"
android:cropToPadding="true"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:paddingLeft="0.5dp"
android:scaleType="centerCrop" />
<!-- WAS: android:padding="0.5dp" -->
<LinearLayout
android:id="@+id/article_row"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@id/article_thumbnail"
android:minHeight="80dp"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="@+id/article_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/articleTitle"
android:textColor="@drawable/list_title_selector"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/article_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/articleSubtitle"
android:textColor="@drawable/list_subtitle_selector"
android:textSize="10sp" />
</LinearLayout>
<WebView
android:id="@+id/article_ad"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="@color/meddark_gray"
android:layout_below="@+id/article_thumbnail"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:padding="10dp" />
</RelativeLayout>