如何在運行時以多行和多列創建多個文本視圖?我已經誇大了線性佈局,並使用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 –