通过代码修改TextView的宽度

//获取屏幕分辨率
     DisplayMetrics dm = new DisplayMetrics();
     getWindowManager().getDefaultDisplay().getMetrics(dm);

 

TextView txtContent = (TextView)findViewById(R.id.txtContent);
     TextView txtDateTime = (TextView)findViewById(R.id.txtDateTime);
     int width_Content = (int) (dm.widthPixels  * 0.6);
     int width_DateTime = (int) (dm.widthPixels  * 0.4);

 

LayoutParams laParaContent = (LayoutParams)txtContent.getLayoutParams();
     laParaContent.width = width_Content;
     txtContent.setLayoutParams(laParaContent);
     
  LayoutParams laParaDT = (LayoutParams)txtDateTime.getLayoutParams();
  laParaDT.width = width_DateTime;
  txtDateTime.setLayoutParams(laParaDT);

你可能感兴趣的:(android)