Drag and drop the layout in Android, as in facebook for the Android application

I tried to implement Facebook as a drag and drop by changing the layout fields, however they always leave traces even if I call invalidate in the view

Facebook for android / ios does this, I wonder how they did it, everywhere I see that only images are dragged and dropped

I am trying to implement something like this , however it leaves traces in my application

package com.example.dragdemo; @SuppressLint({ "NewApi", "ParserError", "ParserError" }) public class MainActivity extends Activity { TextView x; TouchExampleView tex; Context ctx=MainActivity.this; private float mPosX=0; private float mPosY=0; private float mLastTouchX; private float mLastTouchY; LinearLayout redLinear; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tex=new TouchExampleView(ctx); redLinear=(LinearLayout)findViewById(R.id.newLinear); redLinear.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { //Log.e("action is ", event.getAction()+""); if(event.getAction()==MotionEvent.ACTION_MOVE) { //Toast.makeText(ctx, "comes in move", Toast.LENGTH_SHORT).show(); if(((mPosX-(int) event.getX())>2002)||((mPosX-(int) event.getX())<2002)){ mPosX=(int) event.getX(); RelativeLayout.LayoutParams rl=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); //rl.addRule(RelativeLayout., anchor) rl.setMargins((int) event.getX(), 0, 0, 0); redLinear.setLayoutParams(rl); redLinear.invalidate(); } } return true; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } 
+4
source share
1 answer

Jeremy Feinstein’s rolling menu library is a great menu-style implementation of the Facebook app for Android. You have no problem with the trails. You can find it here:

SlidingMenu on github.

0
source

Source: https://habr.com/ru/post/1446216/


All Articles