XML code
<ImageView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:id="@+id/imageView"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/pz"
            android:layout_marginTop="5dp" />
I wrote it like this in java
    ImageView imageView = new ImageView(MainActivity.this);
    imageView.setImageResource(R.drawable.pz);
    DisplayMetrics displaymetrics = new DisplayMetrics();
    MainActivity.this.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int width = displaymetrics.widthPixels;
    int height = 300;
    imageView.setLayoutParams(new ViewGroup.LayoutParams(width, height));
    imageView.setId(i + 1);
    li.addView(imageView);
But it looks strange , i want to change height to eg. 200 , instead of changing height it change width.Is there any better way to make it i just want width to MATCH_PARENT and height to be 200dp?
 
     
    