0
我的要求是,我希望以垂直方式動態顯示三個視圖(即ImageView,TextView,TextView)。想要在android中動態使用垂直方式顯示三個視圖
我確實喜歡下面的程序。但它不是working.Can任意一個幫助me.Please看到下面的代碼
for (int i = 0; i < 10; i++) {
final RelativeLayout relativeLayout=new RelativeLayout(this);
final ImageView imageView=new ImageView(this);
imageView.setId(100+i);
imageView.setBackgroundResource(R.drawable.ic_launcher);
final RelativeLayout.LayoutParams newParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
relativeLayout.post(new Runnable() {
@Override
public void run() {
relativeLayout.addView(imageView);
}
});
final TextView textView=new TextView(this);
textView.setId(200+i);
String data="Click"+"\n"+"Show";
textView.setText("click");
newParams.addRule(RelativeLayout.BELOW, imageView.getId());
newParams.addRule(RelativeLayout.ALIGN_LEFT, imageView.getId());
relativeLayout.post(new Runnable() {
@Override
public void run() {
relativeLayout.addView(textView, newParams);
}
});
final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
final TextView text=new TextView(this);
text.setId(200+i);
//String data="Click"+"\n"+"Show";
text.setText("data");
params.addRule(RelativeLayout.BELOW, textView.getId());
params.addRule(RelativeLayout.ALIGN_LEFT, textView.getId());
relativeLayout.post(new Runnable() {
@Override
public void run() {
relativeLayout.addView(text, params);
}
});
linearLayout.post(new Runnable() {
@Override
public void run() {
linearLayout.addView(relativeLayout);
}
});
}
你有沒有考慮過使用方向設置爲垂直的'LinearLayout'? –
如何設置垂直線性佈局使用代碼。現在感謝我得到了輸出適當的 – user2587727
首先你可以發佈圖像的某個地方向我們展示什麼是你的記憶,其次是這種情況ListView更好... – Selvin