[英]How to display RelativeLayout and ImageView on Android?
我已經動態添加了RelativeLayout和ImageView,但是當我運行該應用程序時,它並沒有顯示在模擬器中。 為什么?
我的代碼:
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的位置設置為其父對象的中心,左側,底部等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.