dynamic layout change during runtime
Posted
by Nils
on Stack Overflow
See other posts from Stack Overflow
or by Nils
Published on 2010-05-25T00:51:00Z
Indexed on
2010/05/25
1:11 UTC
Read the original article
Hit count: 556
android
|absolutelayout
Hello,
for an application I need to place some objects at the exact position that I want to have them and therefore I need to use AbsoluteLayout this time.
I want to add buttons dynamically exactly like in the following XML - but during runtime.
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/backbutton"
android:text="TEST123"
android:layout_x="120px"
android:layout_y="120px"
android:layout_width="100px"
android:layout_height="100px" />
</AbsoluteLayout>
How can I archive this? I tried it with the following code to add a button, but I haven't found a function so far to set layout_x and layout_y. How can I do this? Thanks.
AbsoluteLayout al = new AbsoluteLayout(this);
Button t = new Button(this);
t.setHeight(300);
t.setWidth(300);
t.setText("TEST123");
// x y ???
setContentView(al);
© Stack Overflow or respective owner