亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 C# 中的 Android Xamarin 中設置按鈕的布局寬度?

如何在 C# 中的 Android Xamarin 中設置按鈕的布局寬度?

C#
呼啦一陣風 2022-01-09 17:39:19
我正在使用 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);


查看完整回答
反對 回復 2022-01-09
  • 1 回答
  • 0 關注
  • 343 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號