【发布时间】:2019-03-14 15:23:39
【问题描述】:
我有一个带有 setOntouchlistener 的 imageview。当图像被触摸时,将在展开的底部页面中显示有关触摸区域的信息。
当我运行应用程序时,所有内容最初都按预期显示,我可以看到屏幕底部的 bottomSheet,它显示在 imageView 上方。
但是,一旦我触摸屏幕,图像视图就会显示在底页上,因此我看不到底页。
当我注释掉 imageview 的 setOnTouchListener 时,这不再是问题。我也尝试使用片段来解决同样的问题。任何人都可以为此提出一些解决方案吗?
我尝试在底部表的线性布局和底部表中的图像视图中添加一个触摸监听器。 with return false 但不能解决问题。
以下是重要代码片段的摘录。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
android:padding="@dimen/activity_margin"
app:behavior_hideable="true"
app:behavior_peekHeight="50dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:weightSum="3">
</LinearLayout>
<ImageView
android:id="@+id/fragmentImageView"
android:layout_width="match_parent"
android:layout_height="173dp"
android:src="@android:drawable/btn_star_big_on" />
<TextView
android:id="@+id/locationInfoTextView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="173dp"
android:text="Smellybottom" />
</LinearLayout>
我活动中的 setOntouchListener
photoview2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
touchX = (int) event.getX();
touchY = (int) event.getY();
///##frag//LocationInfoFragment fragobject2 = (LocationInfoFragment) getSupportFragmentManager().findFragmentById(R.id.infoFragment) ;
///##frag//LinearLayout infoFragementLayout = (LinearLayout) findViewById(R.id.infoFragmentLayout);
sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
ImageView fragmentImageView = (ImageView) findViewById(R.id.fragmentImageView);
TextView locationInfoTextView = (TextView)findViewById(R.id.locationInfoTextView);
///##frag//infoFragementLayout.setVisibility(View.INVISIBLE);
for (InfoLocationInformation locationArrayVariable : mInfoLocationInformations) {
if(touchX > locationArrayVariable.getXy().get(0) & touchX < locationArrayVariable.getXy().get(2) & touchY > locationArrayVariable.getXy().get(1) & touchY < locationArrayVariable.getXy().get(3)){
//Log.e(TAG, "Location information for " + locationArrayVariable.getName() );
if(locationArrayVariable.getType()<1 && infoButton.getBackgroundTintList().getDefaultColor()==-49023+100){
locationInfoTextView.setText(locationArrayVariable.getText());
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}else if(locationArrayVariable.getType()>0 && locationArrayVariable.getType()<3 && (barButton.getBackgroundTintList().getDefaultColor()==-524991+100 || restaurentButton.getBackgroundTintList().getDefaultColor()==-10879633+100)){
locationInfoTextView.setText(locationArrayVariable.getText());
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}else if(locationArrayVariable.getType()>2 && locationArrayVariable.getType()<5 && (cafeButton.getBackgroundTintList().getDefaultColor()==-31949+100 || restaurentButton.getBackgroundTintList().getDefaultColor()==-10879633+100)){
//fragmentImageView.setImageBitmap();
locationInfoTextView.setText(locationArrayVariable.getText());
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}else if(locationArrayVariable.getType()>4 && cafeButton.getBackgroundTintList().getDefaultColor()==-31949+100){
locationInfoTextView.setText(locationArrayVariable.getText());
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
}
Log.e(TAG, "touch coordinates X" + touchX +" Y "+ touchY );
ImageView view = (ImageView) v;
view.bringToFront();
viewTransformation(view, event);
return true;
}
});
活动的 .xml。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:design="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/limerickMapImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/limerickmap" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/centreButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="@drawable/centre"
app:backgroundTint="@color/linkBlue" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/restaurentButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginLeft="16dp"
android:layout_marginRight="270dp"
android:layout_marginBottom="570dp"
android:src="@drawable/restaurent"
app:backgroundTint="@color/green1" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/barButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginLeft="16dp"
android:layout_marginRight="340dp"
android:layout_marginBottom="570dp"
android:src="@drawable/bar"
app:backgroundTint="@color/blue3" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginLeft="16dp"
android:layout_marginRight="138dp"
android:layout_marginBottom="570dp"
android:src="@drawable/info" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/cafeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginLeft="16dp"
android:layout_marginRight="205dp"
android:layout_marginBottom="570dp"
android:src="@drawable/cafe"
app:backgroundTint="@color/orange1" />
<include
layout="@layout/bottom_sheet"
/>
【问题讨论】:
标签: java android xml android-fragments