我有一个大型的自定义ImageView,其中的区域被定义为热点。当用户触摸图像上的热点时,我希望向他们提供一个适合所选热点的选项列表。为了最大化图像可用的空间,我在SlidingDrawer中展示了这些选项。
一旦我碰到热点,滑动抽屉覆盖的区域就会停止产生OnTouchEvent回调,即使SlidingDrawer仍然关闭。一旦我手动打开和关闭滑动抽屉,我可以得到一个单一的回调。然而,在滑动抽屉手柄两边的图像顶部的区域(这永远不会被SlidingDrawer覆盖)继续产生回调。
我尝试了以下几点,但都没有成功:
中
如果我以编程方式将ViewState的SlidingDrawer设置为"gone",那么在关闭SlidingDrawer时,所有的热点都会生成OnTouchEvent回调。
下面是布局描述:
<company.views.CustomDetailView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xsns="http://schemas.android.com/apk/res/com.xactware.xactscopedroid"
android:id="@+id/ref_search_detail_view"
style="@style/BaseFullLayout.Vertical">
<company.views.CustomImageView
android:id="@+id/full_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<SlidingDrawer
android:id="@+id/drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:handle="@+id/handle"
android:content="@+id/content"
android:focusableInTouchMode="false">
<TextView
android:id="@id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_xlarge"
android:textColor="@color/dark_gray"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/shape_data_background"
android:focusableInTouchMode="false" />
<ListView
android:id="@id/content"
style="@style/ScopeList.ListView" />
</SlidingDrawer>
下面是用于设置映像、选项列表和OnHotSpotSelected回调的代码。
private void LoadImage(ParentTopic pTopic)
{
if (_imageView == null)
{
_imageView = FindViewById<RefSearchImageView>(Resource.Id.full_image);
}
string imgPath = pTopic.FullImage;
if (imgPath != null)
{
var stream = Context.Assets.Open(System.IO.Path.Combine("en-USrefSearch", pTopic.FullImage));
Bitmap bmp = BitmapFactory.DecodeStream(stream);
_imageView.SetImageBitmap(bmp);
_imageView.PTopic = pTopic;
_imageView.OnHotSpotSelected = new HotSpotSelectedDelegate(OnHotSpotSelected);
}
}
private void LoadList()
{
if (_parentHeaderLabel == null)
{
_parentHeaderLabel = FindViewById<TextView>(Resource.Id.handle);
}
if (Resources.Configuration.Orientation == Android.Content.Res.Orientation.Landscape)
{
_slidingDrawer = FindViewById<SlidingDrawer>(Resource.Id.drawer);
//_slidingDrawer.Visibility = ViewStates.Gone;
}
_parentHeaderLabel.Text = null;
if (_listView == null)
{
_listView = FindViewById<ListView>(Resource.Id.content);
}
if (_currentHeaderList != null)
{
_currentHeaderList.Clear();
}
LayoutInflater inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);
View emptyView = inflater.Inflate(Resource.Layout.RefSearchDetailEmptyList, _listView, false);
_listView.EmptyView = emptyView;
var ia = Context as ItemsActivity;
_listView.OnItemClickListener = new OnRSHeaderClickListener(ia, _currentHeaderList);
}
public void OnHotSpotSelected(string code)
{
ItemsActivity ia = Context as ItemsActivity;
RSParentHeader parentHeader = ia.Data.GetRSParentHeader(code);
_parentHeaderLabel.Text = parentHeader.Desc;
_currentHeaderList = ia.Data.GetRSHeaders(parentHeader.ID);
_listView.Adapter = new RSHeaderListAdapter(Context, Resource.Layout.RSHeaderListItem, Resource.Id.rsheader_desc, _currentHeaderList);
_imageView.Invalidate();
_imageView.RequestFocus();
}发布于 2012-04-20 16:46:04
我仍然不知道为什么,但ListView,这是我的SlidingDrawer的内容,继续消费TouchEvents,即使抽屉关闭。我创建了一个定制的ListView,并重写了OnTouchEvent()来告诉它不要这样做。
public override bool OnTouchEvent (MotionEvent e){
bool consumed = base.OnTouchEvent (e);
SlidingDrawer drawer = (SlidingDrawer)this.Parent;
if (!drawer.IsOpened)
{
return false;
}
return consumed;
}https://stackoverflow.com/questions/9705612
复制相似问题