0
將TableLayout添加到父LinearLayout時遇到問題。 只有第一個視圖被添加到LinearLayout。 我想創建與response.length()一樣多的TableLayouts,然後將它們添加到父LinearLayout。將多個視圖添加到LinearLayout android
這裏的Java代碼:
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.pendingReservations);
for (int i = 0; i < response.length(); ++i) {
final TableLayout tableLayout = (TableLayout) LayoutInflater.from(getApplicationContext()).inflate(R.layout.confirm_reservation_view,null);
//set the TableLayout content
linearLayout.addView(tableLayout,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
的佈局XML代碼:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollViewConfirmRes"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.konrad.rezerwacje1.ConfirmReservation">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/pendingReservations"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>
TableLayout:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/confirmReservationTableLayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:stretchColumns="1">
<!-- TableLayout content -->
</TableLayout>
我已經解決了這個問題,這是我的線性佈局的方向錯誤 – KonradK