触摸屏幕后,带有onTouchListener的imageView后面不可见BottomSheet

时间:2019-03-14 15:23:39

标签: java android xml android-fragments

我有一个带有setOntouchlistener的图像视图。当触摸图像时,将显示展开的底页中有关触摸区域的信息。

当我运行该应用程序时,所有内容最初都按预期显示,我可以在屏幕底部看到在图像底部显示的bottomSheet的一览表。

但是,一旦我触摸屏幕,图像视图就会显示在底部页面上方,因此我看不到底部页面。

当我为imageview注释掉setOnTouchListener时,这不再是问题。我也尝试使用片段来导致完全相同的问题。有人可以为此建议一些解决方案吗?

我尝试将触摸侦听器添加到bottomSheet的LinearLayout和底部工作表中的imageview中。带有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"
     />

1 个答案:

答案 0 :(得分:0)

我删除的简单解决方案       view.bringToFront();