繁体   English   中英

Android-在API> 11中可以移动视图,但是在较低版本中无法运行

[英]Android - Moving a View around works in API > 11 but fails with lower versions

我有一个简单的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lrrh_top_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="0.235" />
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="0.22">
            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="0.05" />
            <TextView
                android:id="@+id/lrrh_red_dress"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.14"
                android:background="@drawable/lrrh_seq01_obj_red_dress" />
            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="0.79" />
        </LinearLayout>
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="0.565" />
    </LinearLayout>
    <TextView
        android:id="@+id/lrrh_drag_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/lrrh_seq01_obj_red_dress"
        android:visibility="invisible" /> </FrameLayout>

每当我在屏幕上移动TextView的地方。 为此,我在TextView上设置了on事件以捕获“ Touch”事件,然后将其设置为可见在另一层上的另一个textview并进行移动。 它适用于API> 11,但不适用于以下任何版本。 怎么会?

    TextView redDress = FindViewById<TextView>(Resource.Id.lrrh_red_dress);

    redDress.Touch += (s, e) =>
    {
        TextView touched = (TextView) s;
        TextView dragItem = FindViewById<TextView>(Resource.Id.lrrh_drag_item);

        int x = (int)e.Event.RawX;
        int y = (int)e.Event.RawY;
        switch (e.Event.ActionMasked)
        {
            case MotionEventActions.Move:
                touched.Visibility = ViewStates.Invisible;
                dragItem.SetBackgroundDrawable(touched.Background);
                int width = touched.Width;
                int height = touched.Height;
                dragItem.Visibility = ViewStates.Visible;
                x -= (dragItem.Width / 2);
                y -= (dragItem.Height / 2);
                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(new ViewGroup.MarginLayoutParams(width, height));
                lp.SetMargins(x, y, 0, 0);
                dragItem.LayoutParameters = lp;
                break;
        }
    };

知道为什么吗?

仅将RelativeLayout与一个TestView一起使用。处理触摸事件并更改文本视图边距。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM