Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【问答】怎么限制FlexboxLayout的行数呢? #638

Open
glad51 opened this issue Aug 4, 2017 · 13 comments
Open

【问答】怎么限制FlexboxLayout的行数呢? #638

glad51 opened this issue Aug 4, 2017 · 13 comments

Comments

@glad51
Copy link

glad51 commented Aug 4, 2017

就是要限制 FlexboxLayout的行数为4行,多出来的数据就不在显示。我现在用获取FlexboxLayout的高度和子控件的高度来判断,是否添加到FlexboxLayout。但是,FlexboxLayout的getMeasuredHeight 一直是109。没有变化。有没有人好的想法呢?

@glad51 glad51 changed the title 怎么限制FlexboxLayout的行数呢? 【求助】怎么限制FlexboxLayout的行数呢? Aug 4, 2017
@glad51 glad51 changed the title 【求助】怎么限制FlexboxLayout的行数呢? 【问答】怎么限制FlexboxLayout的行数呢? Aug 4, 2017
@Fengcoder
Copy link

目前好像没有对应的办法 ,不过如果子元素高度知道的会 ,设置一下maxheight 可以满足

@yubaokang
Copy link

解决了吗?我也遇到这个问题

@diov
Copy link

diov commented Sep 27, 2017

如果业务只是需要 FlexboxLayout 的流式布局,又希望限制行高的话,用你现在的方式还不如直接自定义 ViewGroup 来实现。

另外,FlexboxLayout 的 issue 里面也有人提出希望有一个 maxline 的属性

@ghost
Copy link

ghost commented Aug 23, 2018

也不能获取flexboxlayout的行数。

@syzhugh
Copy link

syzhugh commented Oct 11, 2018

也不能获取flexboxlayout的行数。

1.0.0已经支持了

@AnyLifeZLB
Copy link

AnyLifeZLB commented Dec 20, 2018

设置了MAXLINE=2.第2行后面显示不下的ITEM 都挤压到第2行了,是我配置不对吗? 我是 1.0 版本 FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(this);
flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP); //
flexboxLayoutManager.setFlexDirection(FlexDirection.ROW); //主轴项目排列方向
flexboxLayoutManager.setAlignItems(AlignItems.CENTER);
flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START); //对齐的方式,居中
flexboxLayoutManager.setMaxLine(2); // 配合RECYCLERVIEW

@syzhugh
Copy link

syzhugh commented Dec 21, 2018

设置了MAXLINE=2.第2行后面显示不下的ITEM 都挤压到第2行了,是我配置不对吗? FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(this);
flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP); //
flexboxLayoutManager.setFlexDirection(FlexDirection.ROW); //主轴项目排列方向
flexboxLayoutManager.setAlignItems(AlignItems.CENTER);
flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START); //对齐的方式,居中
flexboxLayoutManager.setMaxLine(2); // 配合RECYCLERVIEW

好像有这个问题。。。那么setMaxLine并没什么卵用的样子
我这边是重写layoutmanager,一个一个测量摆放了。过程就跟viewGroup摆放控件似的。

@wangqm1993
Copy link

tAlignItems(AlignItems.CENTER);
flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START); //对齐的方式,居中
flexboxLayoutManager.setMaxL

设置了MAXLINE=2.第2行后面显示不下的ITEM 都挤压到第2行了,是我配置不对吗? FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(this);
flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP); //
flexboxLayoutManager.setFlexDirection(FlexDirection.ROW); //主轴项目排列方向
flexboxLayoutManager.setAlignItems(AlignItems.CENTER);
flexboxLayoutManager.setJustifyContent(JustifyContent.FLEX_START); //对齐的方式,居中
flexboxLayoutManager.setMaxLine(2); // 配合RECYCLERVIEW

好像有这个问题。。。那么setMaxLine并没什么卵用的样子
我这边是重写layoutmanager,一个一个测量摆放了。过程就跟viewGroup摆放控件似的。

你好,可以参考下代码吗

@oyty
Copy link

oyty commented Feb 27, 2019

check this: google/flexbox-layout#156 (comment)

@ReeCod
Copy link

ReeCod commented Sep 28, 2020

可以设置RecyclerView的高度来限制行数,android:layout_height="xxdp"

@githubZYQ
Copy link

如何限制超过两行末尾加省略号呢?

@jinweime
Copy link

这是我的解决方案:

/**
 * FlexboxLayout设置maxLines之后,如果item超出maxLines,会全部罗列在最后一行,不符合需求;
 *
 * FlexBoxLayoutMaxLines支持设置MaxLines,并截断超出MaxLines的内容;
 */
public class FlexBoxLayoutMaxLines extends FlexboxLayout {
    private int maxLines = NOT_SET;

    @Override
    public void setMaxLine(int maxLine) {
        maxLines = maxLine;
    }

    public int getMaxLines() {
        return maxLines;
    }

    /**
     * see {@link #getMaxLines()}
     */
    @Deprecated
    @Override
    public int getMaxLine() {
        return NOT_SET;
    }

    public FlexBoxLayoutMaxLines(Context context) {
        this(context, null);
    }

    public FlexBoxLayoutMaxLines(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FlexBoxLayoutMaxLines(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setMaxLine(super.getMaxLine());
        super.setMaxLine(NOT_SET);
    }

    @Override
    public List<FlexLine> getFlexLinesInternal() {
        List<FlexLine> flexLines = super.getFlexLinesInternal();
        int size = flexLines.size();
        if (maxLines > 0 && size > maxLines) {
            flexLines.subList(maxLines, size).clear();
        }
        return flexLines;
    }
}

完美解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

13 participants