TrinityTuts Tips

Set ImageView height according to screen in android

In tip learn how we to set ImageView height according to screen size in android. I am setting ImageView height inside ListView header as shown bellow

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;

height = (height * 4) / 10;
Log.e("here", "+++height" + height + "--" + width);
ImageView imageHeaderView = new ImageView(this);
imageHeaderView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.pet_profile_1));
imageHeaderView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageHeaderView.setLayoutParams(new AbsListView.LayoutParams(width, height));

listView.addHeaderView(imageHeaderView, null, false);