flexbox-layout icon indicating copy to clipboard operation
flexbox-layout copied to clipboard

layout_flexBasisPercent and Math.round a problem

Open ttdazi opened this issue 6 years ago • 3 comments

  • [ ] I have searched existing issues and confirmed this is not a duplicate

Issues and steps to reproduce

当我设置FlexboxLayout的宽度为524px的时候,5个子view设置layout_flexBasisPercent=“20%” 结果却换行了?。预估原因。FlexboxHelper中 childMainSize = Math.round(mainSize * flexItem.getFlexBasisPercent()); 每个View的宽度应该是104.8px。而事实是105px。结果造成了最后一个换行。

第一步:设置 FlexboxLayout的layout_width为524px。flexWrap="wrap"。 第二部: 子View设置layout_flexBasisPercent=“20%”

Expected behavior

应该不换行才对的。现在却换行了

Version of the flexbox library

com.google.android:flexbox:1.0.0

Link to code

<com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/flexbox_layout" android:layout_width="524px" android:layout_height="match_parent" app:alignContent="flex_start" app:alignItems="flex_start" app:flexWrap="wrap" tools:showIn="@layout/activity_main">

<TextView
    android:id="@+id/textview1"
    style="@style/FlexItem"
    android:layout_width="@dimen/flex_item_length2"
    android:layout_height="@dimen/flex_item_length"
    android:text="@string/one"
    app:layout_flexBasisPercent="20%" />

<TextView
    android:id="@+id/textview2"
    style="@style/FlexItem"
    android:layout_width="@dimen/flex_item_length3"
    android:layout_height="@dimen/flex_item_length"
    android:text="@string/two"
    app:layout_flexBasisPercent="20%" />

<TextView
    android:id="@+id/textview3"
    style="@style/FlexItem"
    android:layout_width="@dimen/flex_item_length"
    android:layout_height="@dimen/flex_item_length"
    android:text="@string/three"
    app:layout_flexBasisPercent="20%" />

<TextView
    android:id="@+id/textview4"
    style="@style/FlexItem"
    android:layout_width="@dimen/flex_item_length"
    android:layout_height="@dimen/flex_item_length"
    android:text="@string/three"
    app:layout_flexBasisPercent="20%" />

<TextView
    android:id="@+id/textview5"
    style="@style/FlexItem"
    android:layout_width="@dimen/flex_item_length"
    android:layout_height="@dimen/flex_item_length"
    android:text="@string/three"
    app:layout_flexBasisPercent="20%" />

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

ttdazi avatar May 07 '19 13:05 ttdazi

遇到同样的问题

328629033 avatar May 11 '19 07:05 328629033

解决了吗,同样的问题

a454892215 avatar Aug 28 '19 03:08 a454892215

解决了吗,同样的问题

解决了,就是自己去提前计算宽度。让他能均匀的分配比例。

ttdazi avatar Nov 11 '19 13:11 ttdazi