什么是ImageView的默认布局? [英] What's the default layout of an ImageView?

查看:169
本文介绍了什么是ImageView的默认布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在XML中创建它,在PARAMS layout_width并须layout_height。
那么在Java中code创建的项目?什么是他们的默认布局?
如何设置自己的布局FILL_PARENT或WRAP_CONTENT编程?

解决方案
  

公共无效addView(查看子)   自:API级别1

     

添加一个子视图。如果没有布局参数对孩子已经设置,默认参数为此的ViewGroup是对孩子设置。   参数   子子视图添加   另请参见

  generateDefaultLayoutParams()
 


如果没有额外的参数, addView(查看)使用默认参数(主要是 WRAP_CONTENT )。纵观<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.2_r1.1/android/widget/LinearLayout.java#LinearLayout.generateDefaultLayoutParams%28%29">source code ,

 受保护的LayoutParams [更多...] generateDefaultLayoutParams(){
    如果(mOrientation ==水平){
        返回新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    }否则,如果(mOrientation ==垂直){
        返回新的LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
    }
    返回null;
}
 

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


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;
}

这篇关于什么是ImageView的默认布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆