Note that there are some explanatory texts on larger screens.

plurals
  1. POMoving many layouts on screen
    primarykey
    data
    text
    <p>I have been trying to move the layouts on the screen on Touch , the layout disappears when moved along the right side and towards the bottom of the screen , how to fix this .</p> <p>Here is my code:</p> <pre><code> public class MainActivity extends Activity { int windowwidth; int windowheight; ImageView ima1, ima2; RelativeLayout rely1, rely2; private android.widget.RelativeLayout.LayoutParams layoutParams1, layoutParams; // private android.widget.RelativeLayout.LayoutParams layoutParams ; // private android.widget.RelativeLayout.LayoutParams layoutParams ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); windowwidth = getWindowManager().getDefaultDisplay().getWidth(); windowheight = getWindowManager().getDefaultDisplay().getHeight(); System.out.println("width" + windowwidth); System.out.println("height" + windowheight); rely1 = (RelativeLayout) findViewById(R.id.rel1); rely1.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { layoutParams = (RelativeLayout.LayoutParams) rely1 .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(); System.out.println("value of x" + x_cord); System.out.println("value of y" + y_cord); if (x_cord &lt; windowwidth - rely1.getWidth()) { layoutParams.leftMargin = x_cord; } if (y_cord &lt; windowheight - rely1.getHeight()) { layoutParams.topMargin = y_cord; } rely1.setLayoutParams(layoutParams); break; default: break; } return true; } }); rely2 = (RelativeLayout) findViewById(R.id.rel2); rely2.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { layoutParams1 = (RelativeLayout.LayoutParams) rely2 .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(); System.out.println("value of x" + x_cord); System.out.println("value of y" + y_cord); if (x_cord &lt; windowwidth - rely2.getWidth()) { layoutParams1.leftMargin = x_cord; } if (y_cord &lt; windowheight - rely2.getHeight()) { layoutParams1.topMargin = y_cord; } // layoutParams1.leftMargin = x_cord-25; // layoutParams1.topMargin = y_cord-25; // layoutParams1.rightMargin = x_cord-25; // layoutParams1.bottomMargin = y_cord-25; rely2.setLayoutParams(layoutParams1); break; default: break; } return true; } }); } </code></pre> <p>}</p> <p>Here is my xml: </p> <pre><code>&lt;RelativeLayout android:id="@+id/rel1" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /&gt; &lt;/RelativeLayout&gt; &lt;RelativeLayout android:id="@+id/rel2" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /&gt; &lt;/RelativeLayout&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload