我正在使用 Xamarin Android C# 項目中的 Android 按鈕。<Button android:id="@+id/btn1" android:layout_width="120dp" android:layout_height="120dp" android:background="@drawable/ButtonImages" android:layout_marginLeft="35dp" /> 在這里,我想從后面的代碼中設置這個Android: layout_width="120dp"和Android: layout_marginLeft="35dp"。我從后面的代碼中獲得了按鈕控件Button btn1 = FindViewById<Button>(Resource.Id.btn1);但無法設置width和marginLeft我怎樣才能做到這一點?
1 回答

慕哥9229398
TA貢獻1877條經驗 獲得超6個贊
尚未測試這是 xamarin,但理想情況下,這應該可以工作,請嘗試更新。在這里,我將高度和重量設置為120dp,您可以根據需要進行修改。也可以通過替換文本來根據需要設置邊距。
Button btn1 = FindViewById<Button>(Resource.Id.btn1);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams (120,120);
params.setMargins(left, top, right, bottom);
btn1.setLayoutParams(params);
- 1 回答
- 0 關注
- 343 瀏覽
添加回答
舉報
0/150
提交
取消