ฉันได้สร้างแอปที่เพิ่ม TextViews และ ImageViews ลงใน TableLayout แบบไดนามิก ฉันกำลังเผชิญกับปัญหาเล็กๆ น้อยๆ อย่างหนึ่ง ฉันไม่สามารถให้ ImageView แสดงแบบอินไลน์กับฟิลด์ TextView ได้ ในส่วนของฉัน ฉันได้รับผลลัพธ์กลับมาจากเซิร์ฟเวอร์และแสดงมันในรูปแบบ
ฉันได้ลองหลายวิธีแล้ว เช่น การตั้งค่าแรงโน้มถ่วงของ TextView ให้อยู่ในแนวตั้งตรงกลางเช่นนี้
ฉันพยายามจำกัดความกว้างของช่องข้อความแต่ไม่ได้ผล
firstRow.setGravity(Gravity.CENTER_VERTICAL);
นี่คือวิธีการเติมแถวของฉัน:
businessNameRow.addView(businessNameField);
ฉันกำลังเพิ่มชุดแบบไดนามิก แต่ละชุดประกอบด้วย 7 แถว TextView และ 1 ImageView ในแต่ละแถวดังนี้:
TableRow firstRow = new TableRow(getActivity().getApplicationContext());
TableRow secondRow = new TableRow(getActivity().getApplicationContext());
TableRow thirdRow = new TableRow(getActivity().getApplicationContext());
TableRow fourthRow = new TableRow(getActivity().getApplicationContext());
TableRow fifthRow = new TableRow(getActivity().getApplicationContext());
TableRow sixthRow = new TableRow(getActivity().getApplicationContext());
TableRow imageRow = new TableRow(getActivity().getApplicationContext());
TableRow seventhRow = new TableRow(getActivity().getApplicationContext());
จากนั้นฉันก็เพิ่มแถวลงในตาราง
final TableLayout tl = (TableLayout)root.findViewById(R.id.tableResultsGPS);
tl.addView(firstRow); //And so on
TableLayout ของฉันถูกวางไว้ใน ScrollView เพื่อให้ฉันสามารถเลื่อนดูรายการผลลัพธ์ได้