Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the default layout of an ImageView?

Tags:

android

layout

When creating it in xml, the params layout_width and layout_height are required.
What about items created in Java code? What's their default layout?
How can I set their layout to fill_parent or wrap_content programmatically?

like image 952
didi_X8 Avatar asked Dec 13 '22 12:12

didi_X8


1 Answers

public void addView (View child) Since: API Level 1

Adds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child. Parameters child the child view to add See Also

generateDefaultLayoutParams()

Without additional parameters, addView(View) uses the default parameters (mostly WRAP_CONTENT). Looking at the source code,

protected LayoutParams  [More ...] generateDefaultLayoutParams() {
    if (mOrientation == HORIZONTAL) {
        return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    } else if (mOrientation == VERTICAL) {
        return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    }
    return null;
}
like image 185
Aleadam Avatar answered Jan 12 '23 02:01

Aleadam