I have added a RelativeLayout and ImageView dynamically, but it's not displaying in the emulator when I run the application. Why?
My code:
RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.freshface_mmm);
relativeLayout.addView(iv,lp);
您需要使用以下方法将相对布局添加到活动中:
setContentView(view, params);
如果要添加视图,则应使用此方法:
ViewGroup relativeLayout = new RelativeLayout(getActivity());
将ImageView的位置设置为其父对象的中心,左侧,底部等。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.