Element superimposed on a Framelayout

2

I put a FrameLayout blue (see image) and I move it with my finger, but it hides when I go over the edge of FrameLayout father, and the idea is that it is always superimposed, but that it is still added in Framelayout father

Current code:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    >

    <FrameLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@color/colorPrimary"
        >

        <FrameLayout
            android:id="@+id/moverFrme"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@android:color/holo_red_dark"></FrameLayout>
    </FrameLayout>

</FrameLayout>

Class moves the Framelayout son with his finger

public class MainActivity extends AppCompatActivity implements View.OnTouchListener {

 FrameLayout move;
        float dX, dY;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            move = (FrameLayout) findViewById(R.id.moverFrme);
            move.setOnTouchListener(this);
        }

        @Override
        public boolean onTouch(View v, MotionEvent e)
        {
            if (v == move && e.getAction() == MotionEvent.ACTION_DOWN)
            {
                dX = v.getX() - e.getRawX();
                dY = v.getY() - e.getRawY();
            }

            if (v == move && e.getAction() == MotionEvent.ACTION_MOVE)
            {
                move.setY(e.getRawY()+dY);
                move.setX(e.getRawX()+dX);
            }
            return true;
        }
    }
    
asked by albertcito 31.01.2017 в 20:19
source

2 answers

2

The solution is to add the following option to Framelayout called activity_main :

android:clipChildren="false"

This is the definition of the property:

  

android: clipChildren Defines whether a child view is limited to drawing   within its limits or not.

    
answered by 31.01.2017 / 23:12
source
0

What you can do is that the big picture is the father of the two framelayouts , that way both would be children only with different sizes and could move freely.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    >
    <FrameLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:scaleType="center"
        android:background="@color/colorPrimary"
        ></FrameLayout>
    <FrameLayout
            android:id="@+id/moverFrme"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginBottom="20dip"
            android:padding="12dip"
            android:layout_gravity="center_horizontal|bottom"
            android:background="@android:color/holo_red_dark"></FrameLayout>

</FrameLayout>
    
answered by 31.01.2017 в 21:51