Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Change absolute position of a view programmatically
    primarykey
    data
    text
    <p>If you use an AbsoluteLayout (I know that it is deprecated, but it was the only way to solve my <a href="https://stackoverflow.com/questions/3438656/android-scrollable-horizontal-and-vertical-imageview-with-buttons-overlayed"> problem</a>) you can give the childViews the tag <code>android:layout_x</code> and <code>android:layout_y</code> to set their absolute position within the <code>AbsoluteLayout</code>.</p> <p>However I don't want to set these information in the xml, because I only know them at runtime. So how can I set these parameters at runtime programmatically? I don't see any method on the View like <code>view.setLayoutX(int x)</code> or something.</p> <p>Here is my XML, which works fine, when I set the <code>layout_x</code> and <code>layout_y</code> values:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myLayout" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;ImageView android:src="@drawable/myImageView" android:layout_width="1298px" android:layout_height="945px" android:layout_x="0px" android:layout_y="0px" /&gt; &lt;Button android:id="@+id/myButton1" android:text="23" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="50px" android:layout_y="300px" android:tag="23"/&gt; &lt;Button android:id="@+id/myButton2" android:text="48" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="50px" android:layout_y="300px" android:tag="48"/&gt; &lt;/AbsoluteLayout&gt; </code></pre> <p>In fact, I don't want to set any button within the xml anymore, but rather retrieve some information via remote and add buttons depending on that information.</p> <p>Here is the part the code I'm using so in my <code>onCreateMethod</code> to add these buttons:</p> <pre><code> for (MyRemoteObject remoteObject: list) { Button button = new Button(this); button.setOnClickListener (listener); button.setTag(remoteObject.id); button.setText(remoteObject.id); // button.setLayoutX(remoteObject.x) ???? // button.setLayoutY(remoteObject.y) ???? myLayout.addView(button); } </code></pre>
    singulars
    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.
 

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