У меня есть работа с макетом. После запроса GET на сервер я хочу динамически добавлять новые элементы в этот макет.Android способ добавить новый xml-макет
Я хочу добавить эти элементы несколько раз, используя for-structure.
элементы, которые я хочу добавить следующие:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@drawable/outer_border"
android:padding="2dp"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/orange"
android:height="40dp"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:text="TW"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:textSize="70px"
android:width="60dp" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_toLeftOf="@+id/checkBox1"
android:text="inca 6 zile"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
Я попытался это:
for(int i = 0; i < homeworkList.size(); i++){
LinearLayout linearLayout = (LinearLayout) currentActivity.findViewById(R.id.linearLayout2);
RelativeLayout newLayout = new RelativeLayout(currentActivity, null, R.style.HomeworkLayout);
TextView text = new TextView(currentActivity);
TextView text1 = new TextView(currentActivity);
text1.setText("da");
text.setText("nu");
newLayout.addView(text1);
newLayout.addView(text);
linearLayout.addView(newLayout, relativeParams);
}
Но никакого результата, те TextView были добавлены, но друг на друга, и относительный макет, который я только что добавил, для него не имеет никакого стиля, который я добавил с помощью R.style.HomeworkLayout.
Каков наилучший способ добавления элементов с таким стильным дизайном? Почему это не работает?
Не могли бы вы объяснить относительную часть вместо добавления учебник ссылку в одиночку? Ссылки не на 100% надежны, и ссылка может не работать в будущем по какой-то причине. – VicJordan