Хочу добавлять в LinearLayout.
<LinearLayout
android:orientation="horizontal"
android:id="@+id/progressBar_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
вот это view
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progress_bar_element"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
>
<View
android:id="@+id/view_separator"
android:layout_width="1dp"
android:layout_height="43dp"
android:background="@color/colorBackgroundDarckGrey"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/view_separator">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progressBar_friend"
android:layout_width="match_parent"
android:layout_height="43dp"
android:visibility="visible"
android:progressDrawable="@drawable/main_activity_progress_bar_background"
/>
<ImageView
android:id="@+id/imageView_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_lock"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>
В коде делаю следующе:
LinearLayout progressConteiner = (LinearLayout) friendCase.findViewById(R.id.progressBar_container);
View progressElement = getLayoutInflater().inflate(R.layout.main_activity_progress_element,null);
progressConteiner.addView(progressElement);
progressConteiner.addView(progressElement);
При добавлении второго элемента ловлю вот это:
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
UPD:
public class CustomProgressBar extends RelativeLayout {
public CustomProgressBar(Context context) {
super(context, null);
View rootView = inflate(context, R.layout.main_activity_progress_element, this);
ProgressBar progressBar = (ProgressBar)rootView.findViewById(R.id.progressBar_friend);
progressBar.setMax(100);
progressBar.setProgress(55);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
}
}
добавляю так, но добавляется только один элемент
LinearLayout progressConteiner = (LinearLayout) friendCase.findViewById(R.id.progressBar_container);
progressConteiner.addView(new CustomProgressBar(this));
progressConteiner.addView(new CustomProgressBar(this));