我的应用程序中有一个按钮。我想以编程方式改变它的位置。我在XML创建了一个按钮,如下所示:以编程方式安卓按钮位置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:text="@+id/Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50px"
android:layout_marginTop="10px"
>
</Button>
</LinearLayout>
假设我想从左边设置按钮的位置为100像素(如layout_marginLeft =“100px的”)。我怎样才能以编程方式做到这一点?请帮我解决问题。
让我来给点... 其实我的布局,包含9个按钮......所以一些按钮有形和无形的基础上,condition..so我要对齐(向左或向右移动)以编程方式...请帮助我 – 2010-07-13 05:02:24
看看这个答案。它清楚地显示了如何设置按钮的边距。 http://stackoverflow.com/a/4594374/525541 – MindWire 2012-06-27 13:03:28