扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

Android LayoutParams鎬庝箞浣跨敤

扬州沐宇科技
2023-08-17 10:12:35
android, layoutparams

Android LayoutParams鏄竴涓敤浜庤缃甐iew鐨勫竷灞€鍙傛暟鐨勭被銆傚畠鏄疺iewGroup.LayoutParams鐨勫瓙绫伙紝鐢ㄤ簬鎸囧畾View鍦ㄥ竷灞€涓殑浣嶇疆鍜屽ぇ灏忋€侺ayoutParams鍙互閫氳繃璋冪敤View鐨剆etLayoutParams鏂规硶鏉ヨ缃€?/p>

浠ヤ笅鏄娇鐢↙ayoutParams鐨勪竴浜涚ず渚嬶細

  1. 璁剧疆View鐨勫搴﹀拰楂樺害锛?/li>
// 鍒涘缓LayoutParams瀵硅薄
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 璁剧疆View鐨凩ayoutParams
view.setLayoutParams(layoutParams);
  1. 璁剧疆View鍦ㄧ埗瀹瑰櫒涓殑浣嶇疆锛?/li>
LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 璁剧疆View鐩稿浜庣埗瀹瑰櫒宸︿笂瑙掔殑浣嶇疆
layoutParams.setMargins(leftMargin, topMargin, 0, 0);
// 璁剧疆View鐨凩ayoutParams
view.setLayoutParams(layoutParams);
  1. 璁剧疆View鐨勬潈閲嶏紙鐢ㄤ簬LinearLayout锛夛細
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 璁剧疆View鐨勬潈閲?/span>
layoutParams.weight = 1;
// 璁剧疆View鐨凩ayoutParams
view.setLayoutParams(layoutParams);
  1. 璁剧疆View鍦≧elativeLayout涓殑瀵归綈鏂瑰紡锛?/li>
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// 璁剧疆View鍦ㄧ埗瀹瑰櫒涓殑瀵归綈鏂瑰紡
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
// 璁剧疆View鐨凩ayoutParams
view.setLayoutParams(layoutParams);

杩欏彧鏄娇鐢↙ayoutParams鐨勪竴浜涘熀鏈ず渚嬶紝浣犲彲浠ユ牴鎹叿浣撶殑闇€姹傛潵璁剧疆View鐨勫竷灞€鍙傛暟銆?/p>

扫码添加客服微信