[英]How to put the View dynamicaly between two LinearLayout?
我已经将此类数据放入LinearView中。 如下面的代码:
public void showResult()
{
//db.open();
//c2 = db.getAllTitles(table_name);
List<TextView> textListWord = new ArrayList<TextView>(tempEmployerList.size());
List<TextView> textListAnswer = new ArrayList<TextView>(tempEmployerList.size());
List<TextView> imageListAnswer = new ArrayList<TextView>(tempEmployerList.size());
//for(int i = 0; i < c.getCount(); i++)
//int limit = tempEmployerList.size();
for(int i = 0; i<=tempEmployerList.size()-1; i++)
{
RelativeLayout innerLayout = new RelativeLayout(this);
innerLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
innerLayout.setBackgroundColor(0x00000000);
// set the Multiple TextView
TextView qWordTV = new TextView(getApplicationContext());
TextView aWordTV = new TextView(getApplicationContext());
TextView aImageView = new TextView(getApplicationContext());
qWordTV.setText("\n"+"1");
qWordTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
qWordTV.setTextColor(0xFFFF0000);
qWordTV.setPadding(3, 0, 0, 0);
aWordTV.setText("\n"+"2");
aWordTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
aWordTV.setGravity(Gravity.CENTER);
aWordTV.setTextColor(0xFFFF0000);
aWordTV.setGravity(Gravity.CENTER);
aWordTV.setPadding(40, 0, 0, 0);
aWordTV.setTextColor(0xFFFF0000);
aImageView.setText("\n"+"3");
aImageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
aImageView.setGravity(Gravity.RIGHT);
aImageView.setTextColor(0xFF000000);
aImageView.setPadding(0, 0, 9, 0);
/**** Any other text view setup code ****/
innerLayout.addView(qWordTV);
innerLayout.addView(aWordTV);
innerLayout.addView(aImageView);
myLinearLayout.addView(innerLayout);
textListWord.add(qWordTV);
textListAnswer.add(aWordTV);
imageListAnswer.add(aImageView);
}
//while (limit==0);
}
现在,我想在这里动态创建简单视图。 。 。 像:
<View android:layout_height="2dip" android:background="#FF000000" />
在xml中。
现在如何动态地使这样的View像线一样? 请帮助我。 谢谢。
View line = new View(getApplicationContext());
line.setBackgroundColor(0xFF000000);
// You may need to convert dip to px here, raw pixels are used in the example:
LayoutParams layoutParams = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, 2);
line.setLayoutParams(layoutParams);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.