Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.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
Android 为什么我的观点在跨越它时消失了';原始的右下界是多少?_Android_Android Layout - Fatal编程技术网

Android 为什么我的观点在跨越它时消失了';原始的右下界是多少?

Android 为什么我的观点在跨越它时消失了';原始的右下界是多少?,android,android-layout,Android,Android Layout,我有一个复合视图。我有一个图像按钮,我想能够左右拖动。我可以把它从原来的位置向左上拖动,它看起来很好。如果我向右或向下移动它的原始位置,按钮就会消失。我已经启用了开发者选项来绘制视图边界。当我移动ImageButton时,我看到左边界和上边界会展开和收缩。右侧和底部没有 在这里,它是左上移动,没有任何问题 在这里,它正从原来的边界向右移动,你可以看到它穿过右边的线时消失了。 我尝试在按钮上设置新的布局参数,但没有看到位置的变化。所以我使用setLeft()和setBottom()。为什么我的

我有一个复合视图。我有一个图像按钮,我想能够左右拖动。我可以把它从原来的位置向左上拖动,它看起来很好。如果我向右或向下移动它的原始位置,按钮就会消失。我已经启用了开发者选项来绘制视图边界。当我移动ImageButton时,我看到左边界和上边界会展开和收缩。右侧和底部没有

在这里,它是左上移动,没有任何问题

在这里,它正从原来的边界向右移动,你可以看到它穿过右边的线时消失了。

我尝试在按钮上设置新的布局参数,但没有看到位置的变化。所以我使用setLeft()和setBottom()。为什么我的按钮不见了

  @OnTouch(R.id.silence_snooze_choice_button)
    public boolean choiceButtonClicked(View v, MotionEvent event){

        //LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) choiceButton.getLayoutParams();
        switch(event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_MOVE:
                int x_cord = (int)event.getRawX();
                int y_cord = (int)event.getRawY();

                DisplayMetrics metrics = getResources().getDisplayMetrics();
                int width = metrics.widthPixels;
                int height = metrics.heightPixels;

                Log.i(TAG, String.format("%d,%d", x_cord, y_cord));
                //this didn't work.
                //layoutParams.leftMargin = x_cord -25;
                //layoutParams.topMargin = y_cord - 75;
                //choiceButton.setLayoutParams(layoutParams);
                choiceButton.setLeft(x_cord);
                choiceButton.setBottom(y_cord);

                break;
            default:
                break;
        }
        return true;
    }
这是我的视图上方的布局。CircleDragSelector是复合视图的名称

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="180dp"
    android:background="@color/primary"
    >

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_margin="16dp"
        android:layout_centerVertical="true"
        android:src="@drawable/abc_ic_menu_paste_mtrl_am_alpha"
        />

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_margin="16dp"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_action_share"
        />

    <ImageButton
        android:id="@+id/silence_snooze_choice_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_play_circle_outline"
        />

</RelativeLayout>

这是父布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <SurfaceView
        android:id="@+id/surface_view_camera_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <View
        android:id="@+id/view_transparent_overlay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffff"
        android:alpha="0.85"/>


    <TextView
        android:id="@+id/alarm_screen_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="28dp"
        android:textSize="36sp"
        android:textColor="@color/accent_material_dark"
        android:text="Alarm name" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/alarm_screen_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/alarm_screen_name"
        android:layout_marginTop="28dp"
        android:layout_centerHorizontal="true"
        android:text="00 : 00"
        android:textSize="52dp"
        android:textColor="@color/accent_material_dark"
        />



    <ImageButton
        android:id="@+id/alarm_screen_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="50dp"
        android:src="@drawable/ic_cancel_black_48dp"
        android:background="@null"
        android:text="Dismiss"
        android:textSize="28dp" />

    <com.example.tyler.rollout.views.CircleDragSelector
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    </com.example.tyler.rollout.views.CircleDragSelector>




</RelativeLayout>

默认情况下,布局会剪裁其子布局,这意味着默认情况下会隐藏负边距之类的内容

放置

<RelativeLayout 
...
clipChildren="false">


在父布局上,应该可以解决此问题。

您尝试过在父布局上设置clipChildren=false吗?@BenNeill成功了!