【发布时间】:2011-03-14 18:47:53
【问题描述】:
我的应用程序中有一个按钮。我想以编程方式改变它的位置。我在 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>
假设我想将按钮的位置设置为距左侧 100px(如 layout_marginLeft="100px")。我怎样才能以编程方式做到这一点?请帮我解决问题。
【问题讨论】:
-
填充和边距不一样...这是线程是您正在寻找的stackoverflow.com/questions/2481455/…
-
让我进入正题...实际上我的布局包含 9 个按钮...所以根据条件有些按钮可见和不可见..所以我想对齐(向左或向右移动)它以编程方式...请帮助我
-
看看这个答案。它清楚地显示了如何在按钮上设置边距。 stackoverflow.com/a/4594374/525541