Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-出现在ImageView后面的片段_Java_Android_Xml_Android Fragments - Fatal编程技术网

Java Android-出现在ImageView后面的片段

Java Android-出现在ImageView后面的片段,java,android,xml,android-fragments,Java,Android,Xml,Android Fragments,我在活动中有一个ImageView,当您单击图像的一部分时,片段将更新并可见。这可以根据需要工作,但是片段显示在imageView后面。所以我看不见。我希望片段出现在视图的底部三分之一处。有人能解释为什么会发生这种情况吗 .xml文件 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://sc

我在活动中有一个ImageView,当您单击图像的一部分时,片段将更新并可见。这可以根据需要工作,但是片段显示在imageView后面。所以我看不见。我希望片段出现在视图的底部三分之一处。有人能解释为什么会发生这种情况吗

.xml文件

 <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" />



<LinearLayout
    android:id="@+id/infoFragmentLayout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
    android:visibility="invisible"
     >

    <fragment
        android:id="@+id/infoFragment"
        class="com.codingwithmitch.googlemaps2018.ui.LocationInfoFragment"
        android:layout_width="fill_parent"
        android:layout_height="300dp"
        android:layout_gravity="bottom"
        app:layout_anchorGravity="center_vertical" />
</LinearLayout>

看到您的需求,您应该选择BottomSheetFragment,这将是满足您需求的完美解决方案

检查以下链接


看到您的需求,您应该选择BottomSheetFragment,这将是满足您需求的完美解决方案

检查以下链接


有一种方法可以在主坐标视图中克服此问题,将其背景色设置为白色并使其可单击

有一种方法可以在主坐标视图中克服此问题,将其背景色设置为白色并使其可单击

这非常好,但是它仍然默认在我的imageview后面。你可以共享快照吗?我没有这个特权,我只是看不到片段/底页,因为imageview阻止了它。我相信另一个答案中的拉杰是正确的。这可能是因为我在图像视图上有一个单击侦听器。这很好,但它仍然默认在我的imageview后面。你可以共享快照吗?我没有这个特权,我只是看不到片段/底页,因为imageview阻止了它。我相信另一个答案中的拉杰是正确的。这可能是因为我在图像视图上有一个单击侦听器。主坐标视图?这是我的活动布局文件吗?无论哪个xml位于顶部,都要使其可单击,并将背景设置为白色,如#fffmain坐标视图?这是我的活动布局文件吗?无论哪个xml位于顶部,都要使其可点击,并将背景设置为白色,如#fff
  photoview2.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            touchX = (int) event.getX();
            touchY = (int) event.getY();
            LocationInfoFragment fragobject2 = (LocationInfoFragment) getSupportFragmentManager().findFragmentById(R.id.infoFragment) ;
            LinearLayout infoFragementLayout = (LinearLayout) findViewById(R.id.infoFragmentLayout);
            //LinearLayout infoFragementLayout = (LinearLayout) findViewById(R.id.infoFragmentLayout);
            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){

                        bundleString = locationArrayVariable.getText();

                        fragobject2.updateFragment(bundleString);
                        infoFragementLayout.setVisibility(View.VISIBLE);
                    }else if(locationArrayVariable.getType()>0 && locationArrayVariable.getType()<3 && (barButton.getBackgroundTintList().getDefaultColor()==-524991+100 || restaurentButton.getBackgroundTintList().getDefaultColor()==-10879633+100)){
                        bundleString =locationArrayVariable.getText();

                        fragobject2.updateFragment(bundleString);
                        infoFragementLayout.setVisibility(View.VISIBLE);
                    }else if(locationArrayVariable.getType()>2 && locationArrayVariable.getType()<5 && (cafeButton.getBackgroundTintList().getDefaultColor()==-31949+100 || restaurentButton.getBackgroundTintList().getDefaultColor()==-10879633+100)){

                        fragobject2.updateFragment(bundleString);
                        infoFragementLayout.setVisibility(View.VISIBLE);
                    }else if(locationArrayVariable.getType()>4 && cafeButton.getBackgroundTintList().getDefaultColor()==-31949+100){

                        fragobject2.updateFragment(bundleString);
                        infoFragementLayout.setVisibility(View.VISIBLE);
                    }


                }
            }
            Log.e(TAG, "touch coordinates X" + touchX +" Y "+ touchY  );
            ImageView view = (ImageView) v;
            view.bringToFront();
            viewTransformation(view, event);
            return true;
        }
    });
    private void viewTransformation(View view, MotionEvent event) {

    switch (event.getAction() & MotionEvent.ACTION_MASK) {

        case MotionEvent.ACTION_DOWN:

            centreCheck =false;
            xCoOrdinate = view.getX() - event.getRawX();
            yCoOrdinate = view.getY() - event.getRawY();

            start.set(event.getX(), event.getY());
            isOutSide = false;
            mode = DRAG;
            lastEvent = null;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            centreCheck =false;
            oldDist = spacing(event);
            if (oldDist > 10f) {
                midPoint(mid, event);
                mode = ZOOM;
            }

            lastEvent = new float[4];
            lastEvent[0] = event.getX(0);
            lastEvent[1] = event.getX(1);
            lastEvent[2] = event.getY(0);
            lastEvent[3] = event.getY(1);
            d = rotation(event);
            break;
        case MotionEvent.ACTION_UP:
            centreCheck =false;
            isZoomAndRotate = false;
            if (mode == DRAG) {
                float x = event.getX();
                float y = event.getY();
            }
        case MotionEvent.ACTION_OUTSIDE:
            centreCheck =false;
            isOutSide = true;
            mode = NONE;
            lastEvent = null;
        case MotionEvent.ACTION_POINTER_UP:
            centreCheck =false;
            mode = NONE;
            lastEvent = null;
            break;

        case MotionEvent.ACTION_MOVE:
            centreCheck =false;
            if (!isOutSide) {
                if (mode == DRAG) {
                    isZoomAndRotate = false;
                    view.animate().x(event.getRawX() + xCoOrdinate).y(event.getRawY() + yCoOrdinate).setDuration(0).start();
                }
                if (mode == ZOOM && event.getPointerCount() == 2) {
                    float newDist1 = spacing(event);
                    if (newDist1 > 10f) {
                        float scale = newDist1 / oldDist * view.getScaleX();
                        view.setScaleX(scale);
                        view.setScaleY(scale);
                    }
                    if (lastEvent != null) {
                        newRot = rotation(event);
                        view.setRotation((float) (view.getRotation() + (newRot - d)));
                    }
                }
            }
            break;
    }
}