English 中文(简体)
ImageView的默认布局是什么?
原标题:What s the default layout of an ImageView?

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?

最佳回答

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()

在没有其他参数的情况下,addView(View)使用默认参数(主要是WRAP_CONTENT)。查看源代码

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;
}
问题回答

暂无回答




相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...

热门标签