Horizontal scroll view hiding some children
android, horizontalscrollview
Solution
<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
Problem
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 } } ```