如何在运行时以多行和多列创建多个文本视图?我已经夸大了线性布局,并使用for循环创建了文本视图。文本视图已成功创建,但我面临的问题是所有创建的文本视图都只在单行中。我试图用LayoutParams也设置它,但不能修复它。如何解决这个问题?下面是我的代码运行时的Android文本视图 - 文本视图充气为多行
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
appointmentSlotList = appointmentSlot.getAppointmentSlots();
if(appointmentSlotList != null && appointmentSlotList.size()>0){
for(int i = 0; i<appointmentSlotList.size(); i++){
View appointmentInflater = layoutInflater.inflate(R.layout.appointment_time, null);
TextView lblDate = (TextView) appointmentInflater.findViewById(R.id.appointmentTime);
lblDate.setText(appointmentSlotList.get(i));
lblDate.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
//lblDate.setLayoutParams(lparams);
lblDate.setOnClickListener(onclickTime);
try {
//if(previousSelected!=i)
lnrDateContainer.addView(appointmentInflater);
}catch (Exception e){
e.printStackTrace();
}
}
}
和我下面的输出显示:
Output for the inflated text views shown below the date picker
膨胀的LinearLayout父的LinearLayout内部和内部的膨胀textviews在一个循环,这样就可以模拟状结构 – Nilabja
表指定方位的LinearLayout –