View views =
// View v =LayoutInflater.from(MainActivity.this).inflate(
// R.layout.dialog, null);
// LayoutInflater inflater = (LayoutInflater) MainActivity.this
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// View views = inflater.inflate(R.layout.dialog, null);
LinearLayout views = (LinearLayout) getLayoutInflater()
.inflate(R.layout.dialog, null);
new AlertDialog.Builder(MainActivity.this).setTitle("aaaa")
.setView(views).show();
final LinearLayout lin =(LinearLayout)findViewById(R.id.LinearLayout01);
LinearLayout layout = (LinearLayout) inflater.inflate(
R.layout.listview, null).findViewById(R.id.layout);
lin.addView(layout);
View v =LayoutInflater.from(MainActivity.this).inflate(
// R.layout.dialog, null);
setContentView(v);
动态设置布局的宽高
View v =LayoutInflater.from(MainActivity.this).inflate(
// R.layout.dialog, null);
RelativeLayout.LayoutParams albumLay = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
v.setLayoutParams(albumLay);
获取手机的宽高,动态设置布局在屏幕中的比例
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
application.screenWidth = width;
application.screenHeight = height;
RelativeLayout.LayoutParams albumLay = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
albumLay.setMargins(50, (int) ((height * 0.45) * ((height * 0.45) * 0.48 / (height * 0.45))), 50,
0);
findViewById(R.id.album).setLayoutParams(albumLay);