如何動態設置控件的寬高度?

如何動態地控制控件的寬高度呢?以下面的例子所示:app

llShowCheckBtn = (LinearLayout) findViewById(R.id.more_show_message_dialog_ll);.net

LayoutParams lp =llShowCheckBtn.getLayoutParams();get

lp.width = (int)(getScreenWidth() * 0.75);//此處能夠設置爲任意整數,如280,120等等均可以。io

llShowCheckBtn.setLayoutParams(lp);static

/**di

* 得到屏幕的寬度co

new

* @param contextreturn

* @return context

*/

public static int getScreenWidth()

{

DisplayMetrics dm = new DisplayMetrics();

dm = applicationData.getGlobalContext().getResources()

.getDisplayMetrics();

return dm.widthPixels;

}

相關文章
相關標籤/搜索