2016-06-13 11 views
2

私はこれをflexbox layoutを使用しています。私は行動をとどめている。動的に追加されたアイテムがFlexboxLayoutに収まらない場合は、アイテムを次の行に表示します。フレキシボックスがコンテンツを縮小し、アンドロイド:フレックスボックスの包装内容なし

private void generateCategories(UserCategoryListResponse userCategoryListResponse) { 
    for (UserCategoryListResponse.Datum data : userCategoryListResponse.getData()) { 
     mFlexboxLayout.addView(getCategoryRadioButton(data)); 
    } 
} 

private RadioButton getCategoryRadioButton(UserCategoryListResponse.Datum data) { 

    RadioButton radioButton = new RadioButton(this); 
    radioButton.setId(Integer.parseInt(data.getCategoryId())); 
    radioButton.setBackgroundResource(R.drawable.selector_choose_category); 
    radioButton.setButtonDrawable(null); 
    radioButton.setPadding(DisplayUtils.pxToDp(this, 16), DisplayUtils.pxToDp(this, 16), DisplayUtils.pxToDp(this, 16), DisplayUtils.pxToDp(this, 16)); 
    radioButton.setText(data.getCategoryName()); 
    radioButton.setTypeface(radioButton.getTypeface(), Typeface.BOLD); 
    radioButton.setEnabled(data.getIsFree().equals("1")); 
    radioButton.setOnCheckedChangeListener(this); 
    return radioButton; 
} 

しかし、実際に起こって何です:

<com.google.android.flexbox.FlexboxLayout 
    android:id="@+id/fbl_choose_category_upload" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="@dimen/margin_16" 
    android:paddingLeft="@dimen/padding_16" 
    android:paddingRight="@dimen/padding_16" 
    app:alignContent="space_between" 
    app:alignItems="flex_start" 
    app:flexDirection="row" 
    app:flexWrap="wrap" 
    app:justifyContent="space_between"> 

</com.google.android.flexbox.FlexboxLayout> 

私のJavaコード:

enter image description here

Flexbox Version: 0.2.2

以下は私のXMLコードです。期待される結果は、3つのカテゴリのみが最初に適合することができれば、次のアイテムが次のラインに現れるはずであるということです。

誰でも私にこれを手伝うことができます。

答えて

1

私はフレックスボックスレイアウトを試していませんが、私は過去に同じ問題を解決しました。私のアプローチはこれに似ていました。

新しい動的ビューの追加時に、親ビューグループのサイズを画面サイズで確認していましたが、ビューグループのサイズが大きくなると、新しいビューグループを追加してそのビューを新しく追加しましたまたは同じ行にビューを追加するだけでした。

こちらがお役に立てば幸いです。

+0

はいこれは私の代替ソリューションです。 –

関連する問題