以下理解均为错误,因为LayoutParams是属于ViewGroup的,对于一个ViewGroup中的子元素,可以用该ViewGroup的LayoutParams
GridView和Gallery中都有LayoutParams为他们的子View设置参数
ImageView imageView=new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(50, 50));
imageView.setImageResource(mImageIds[position]);
关于普通View设置参数的办法为
LayoutParams params = viewgroup.getLayoutParams();
params.height=50;
params.width=50;
viewgroup.setLayoutParams(params);
以上的LayoutParams是引自ViewGroup的
以上理解均为错误,因为LayoutParams是属于ViewGroup的,对于一个ViewGroup中的子元素,可以用该ViewGroup的LayoutParams
本文深入探讨了LayoutParams在Android中的使用方法,包括其作为ViewGroup的属性如何为子元素设置参数,尤其针对GridView和Gallery组件的具体应用示例。通过实例代码展示了如何灵活地调整子View的尺寸和位置,为开发者提供了实用的布局调整技巧。
7171

被折叠的 条评论
为什么被折叠?



