Search This Blog

Saturday, August 13, 2016

Layout - Cập nhật chiều rộng layout

// lấy chiều rộng
Display display = getWindowManager().getDefaultDisplay();
final int screenweight = display.getWidth();
// ánh xạ
layoutTrangChinh = (LinearLayout) findViewById(R.id.layoutTrangChinh);
layoutYeuThich = (LinearLayout) findViewById(R.id.layoutYeuThich);
// Get params:
LinearLayout.LayoutParams loparams = (LinearLayout.LayoutParams) layoutTrangChinh.getLayoutParams();
LinearLayout.LayoutParams loparams1 = (LinearLayout.LayoutParams) layoutYeuThich.getLayoutParams();

// cập nhật chiều rộng layout
loparams.weight = (screenweight/2 );
loparams1.weight = (screenweight/2 - 10);

// set
layoutTrangChinh.setLayoutParams(loparams);
layoutYeuThich.setLayoutParams(loparams1);

No comments:

Post a Comment