Android4.1.0。
その中に1つの水平スクロールビューがあります- LinearLayout
。LinearLayoutでは、プログラムでフラグメントにいくつかの子を追加しますonResume
。子供たちが視界に収まる場合、すべてがうまくいきます。子がビューに収まらない場合は、HorizontalView
最初のn個の要素を左側から非表示にし、右側にn個の要素用の空き領域を確保します。
computeScroll
またはrequestLayout
/に電話をかけようとしましforceLayout
たが、役に立ちませんでした。
<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>
およびフラグメント内のコード:
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
}
}