Set ImageView’s max width as a percent of its parent’s width

This can’t be done in the XML. You would have to specify the size in the code. I would do that in the onCreate() of the activity:

import android.widget.LinearLayout.LayoutParams;
...
obj.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                     LayoutParams.WRAP_CONTENT,
                                     0.25f));

This means use 100% of the parent’s height but 25% of the parent’s width.

Leave a Comment