gpt4 book ai didi

android - 为什么我的 View 在越过它原来的右边界和下边界时消失了?

转载 作者:行者123 更新时间:2023-11-30 01:46:41 24 4
gpt4 key购买 nike

我有一个复合的观点。我有一个 ImageButton,我希望它能够左右拖动。我可以将它从原来的位置向左和向上拖动,看起来不错。如果我向右或低于其原始位置,按钮就会消失。我启用了开发人员选项来绘制 View 边界。当我移动 ImageButton 时,我看到左边界和上边界扩大和缩小。右侧和底部没有。

在这里它可以毫无问题地向左和向上移动 Here it is moving left and up with no problems

此处它正在向右移动超出其原始边界,您可以看到它在越过右侧线时消失了。 Here it is moving beyond it's original bounds to the right, you can see it disappearing as it crosses the right line.

我已经尝试在按钮上设置新的布局参数,但位置没有变化。所以我正在使用 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;
}

这是我的顶部 View 布局。 CircleDragSelector 是复合 View 的名称。

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

在父布局上应该解决这个问题。

关于android - 为什么我的 View 在越过它原来的右边界和下边界时消失了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33625285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com