我试图在新行中显示每个内容(图像视图和文本视图),但我不能成功。 我是以编程方式进行的,这是我的代码。
RelativeLayout grp=new RelativeLayout(this);
grp.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
grp.setPadding(10, 10, 10, 10);
TextView test=new TextView(this);
test.setPadding(15, 15, 15, 15);
test.setText(Html.fromHtml("<p>text here</p>"));
LinearLayout ln=new LinearLayout(this);
ImageView img=new ImageView(this);
img.setImageResource(R.drawable.imageA);
img.setFadingEdgeLength(10);
ln.addView(img);
ln.addView(test);
ln.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT));
LinearLayout ln0=new LinearLayout(this);
grp.addView(ln);
TextView test1=new TextView(this);
test1.setPadding(15, 15, 15, 15);
test1.setText(Html.fromHtml("<p>text here</p>"));
LinearLayout ln1=new LinearLayout(this);
ImageView img1=new ImageView(this);
img1.setImageResource(R.drawable.imageB);
img1.setFadingEdgeLength(10);
ln1.addView(img1);
//ln1.setPadding(10, 10, 10, 10);
ln1.addView(test1);
ln1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT));
grp.addView(ln1);
setContentView(grp);
我该怎么办?
答案 0 :(得分:0)
使用LinearLayout而不是RelativeLayout,并使用setOrientation(LinearLayout.VERTICAL)将linearlayout的方向设置为vertical;