ITeye博客

GridView 、Gallery以及普通View中LayoutParams的设置

mmdev · 2012-12-11 15:42 · Markdown

以下理解均为错误,因为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


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。