我想添加
ImageView到FrameLayout与重力或边距.但是FramLayout和ImageView没有方法(实际上我找不到).选择Framelayout的原因是将ImageView放在ImageView上.
帮我吧这是紧急情况我找到解决方案.
谢谢.
以下是我的代码,帮助我理解我的问题.
FrameLayout imageFrame = new FrameLayout(mContext); imageFrame.setLayoutParams(new GridView.LayoutParams(158,158)); ImageView frame = new ImageView(mContext); frame = new ImageView(mContext); frame.setLayoutParams(new LayoutParams(158,158)); frame.setScaleType(ImageView.ScaleType.CENTER_CROP); frame.setimageResource(R.drawable.image_frame_n); ImageView image = new ImageView(mContext); image.setLayoutParams(new LayoutParams(148,148)); image.setScaleType(ImageView.ScaleType.CENTER_CROP); image.setimageResource(mThumbIds[position]); // image is needed to have a margin or gravity to be positioned at center of imageFrame imageFrame.addView(image); imageFrame.addView(frame);
解决方法
尝试:
image.setLayoutParams(new FrameLayout.LayoutParams(width,height,gravity));
更多信息:
http://developer.android.com/reference/android/widget/FrameLayout.LayoutParams.html