I placed a FrameLayout
blue (see image) and I move it with my finger, but it is hidden when I go over the edge of the FrameLayout
parent, and the idea is that it is always overlapped, but that it is still added in the Framelayout
parent
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 child Framelayout with its 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;
}
}
The solution is to add the following option to the
Framelayout
call :activity_main
This is the definition of the property:
What you can do is make the big box the parent of the two framelayouts , that way they would both be children only with different sizes and could move around freely .