【问题标题】:Android- Fragment appearing behind ImageViewAndroid-ImageView后面出现的片段
【发布时间】:2019-08-05 05:24:58
【问题描述】:

我在活动中有一个 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>

这是我使片段可见的活动中的 onCreate 的 sn-p

  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;
    }
}

【问题讨论】:

    标签: java android xml android-fragments


    【解决方案1】:

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

    查看以下链接

    https://www.androidhive.info/2017/12/android-working-with-bottom-sheet/

    【讨论】:

    • 这很好,但它仍然默认在我的图像视图后面
    • 你能分享一下快照吗?
    • 我没有这个权限,我根本看不到片段/底页,因为图像视图阻止了它。我相信另一个答案中的 raj 是在正确的轨道上。可能是因为我在图像视图上有一个点击监听器。
    【解决方案2】:

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

    【讨论】:

    • 主坐标视图?这是我的活动布局文件吗?
    • 无论哪个 xml 出现在顶部,都使其可点击并将背景设置为白色 #fff
    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多