Android 4.1.0.
I have one horizontal scroll view, inside it - LinearLayout
.
In LinearLayout I add some children programmatically in fragment onResume
.
In the case when children fit in the view, everything is fine.
In the case when children do not fit in the view, HorizontalView
hides first n elements from the left and keep free space for n elements on the right.
I tried to call computeScroll
or requestLayout
/forceLayout
, but it didn't help.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/productListScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/productListLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingTop="10dp" />
</HorizontalScrollView>
...
</LinearLayout>
and the code in fragment:
public void onResume() {
super.onResume();
productsPanel.removeAllViews();
for (Product product : currentOrder.getProductList()) {
productsPanel.addView(new ...); //view with calculated height and width
productsPanel.addView(new ...); //view with fixed width and height = MATCH_PARENT
}
}
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<LinearLayout android:id="@+id/top_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Lots of items -->
</LinearLayout>
</HorizontalScrollView>
It was issue. Horizontal scroll view hides its children if you set android:layout_gravity="center_horizontal"
for inner container.
link is here
The problem was solved by setting linear layout layout_gravity=left
, gravity=center
.
I also moved view creation code to onActivityCreated
, but I don't think it helped to solve this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With