我已将此类数据放入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" />
in xml。
现在如何使这样的视图像动态线? 请帮帮我。 感谢。
答案 0 :(得分:1)
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);