I add a view to the left of an existing view which is centred in parent. I would like the layout to update and centre both the view I added dynamically to the left of the existing view and the existing view.
I have previously looked at this question and tried to get the view to wrap_content after I have added the view which did not work using:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.LEFT_OF, timePicker.getId());
params.addRule(RelativeLayout.CENTER_VERTICAL);
picker.setLayoutParams(params);
lytBottom.addView(picker);
RelativeLayout.LayoutParams existingParams = (RelativeLayout.LayoutParams) lytBottom.getLayoutParams();
existingParams.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
and tried changing the visibility as per the top suggested comment. All the above did was wrap_content around the view originally there and completely ignores the dynamically added view.
Is there another way I could be approaching this to achieve the centering of both the new view and the old one while keeping the new view to the left of the old view?
The xml:
<android.support.percent.PercentRelativeLayout
android:id="@+id/lytBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/lytTop"
android:layout_centerHorizontal="true"
app:layout_heightPercent="30%">
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:timePickerMode="spinner"/>
</android.support.percent.PercentRelativeLayout>