2016-06-13 2 views
2

이 부분은 flexbox layout입니다. 나는 행동이 달라 붙어있다. 동적으로 추가 된 항목이 FlexboxLayout에 맞지 않으면 항목을 다음 줄에 표시하려고합니다. 인 flexbox이 내용을 축소,android : flexbox 포장 내용이 없습니다

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> 

내 자바 코드 :

enter image description here

Flexbox Version: 0.2.2

다음은 내 XML 코드입니다. 예상되는 결과는 말하자면 3 개의 카테고리 만 처음에 들어 맞을 수 있다면 다음 항목이 다음 줄에 나타나야한다는 것입니다.

누구든지이 문제를 해결할 수 있다면.

답변

1

나는 flexbox 레이아웃을 시도하지 않았지만, 나는 과거에 같은 문제를 해결했다. 나의 접근 방식은 이것과 같았다.

새로운 동적 뷰를 추가 할 때 상위 뷰 그룹의 크기를 화면 크기로 확인하고 뷰 그룹 크기가 커지면 새 뷰 그룹을 추가하고 그 뷰를 새로 추가합니다 생성 된 뷰 그룹 또는 다른 뷰는 같은 ​​행에 뷰를 추가하는 것입니다.

도움이되기를 바랍니다.

+0

예 이렇게하면 제 대안 솔루션이 될 수 있습니다. –

관련 문제