我的應用程序中有一個按鈕。我想以編程方式改變它的位置。我在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