Я tring, чтобы добавить виды макета в scrollView динамически. Я знаю, как использовать ListView, но в этом случае я не хочу использовать ListView. Итак, сначала я раздую макет для просмотра, а затем добавлю его в linearLayout внутри ScrollView. проблема в том, что я не могу добавить время умножения макета.Как добавить виды в scrollview динамически?
View layoutInflated;
ScrollView scrollView;
LinearLayout childView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_matan);
scrollView = (ScrollView) findViewById(R.id.scroll_view_container);
childView = (LinearLayout) findViewById(R.id.linear_row_container);
layoutInflated = getLayoutInflater().inflate(R.layout.row_message, scrollView, false);
childView.addView(layoutInflated);
}
main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:onegravity="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scroll_view_container"
android:layout_gravity="bottom"
android:fillViewport="false" >
<LinearLayout
android:id="@+id/linear_row_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</ScrollView>
</LinearLayout>
макет "строка":
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:onegravity="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:id="@+id/toolBar"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<include android:id="@+id/rte_toolbar_container" layout="@layout/rte_toolbar"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="14.23"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" >
<ImageView
android:id="@+id/row_imgMail"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:scaleType="centerCrop"
android:src="@drawable/icon_google" />
<TextView
android:id="@+id/row_txMailAddres"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:gravity="left|center"
android:text="[email protected]"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="bold" />
<CheckBox
android:id="@+id/row_cbMail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:button="@drawable/checkbox_custom" />
<ImageButton
android:id="@+id/row_btnMagic"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/ic_apply_all_accounts" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/shadow_bottom" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:button="@drawable/checkbox_custom" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Любая идея, как это сделать?
Почему вы не используете ** петли **? :) – waqaslam
Я использую, но приложение падает –
Почему вы используете несколько LinearLayouts? – Biswajit