标签: android-flexboxlayout

使用FlexboxLayoutManager将RecyclerView项目居中

如何RecyclerView使用中心对待所有项目FlexboxLayoutManager?我需要像这样集中的项目:

正确居中的物品

我尝试没有成功: 我的尝试,不正确

我设置布局管理器的代码:

val layoutManager = FlexboxLayoutManager(this)
        layoutManager.setFlexWrap(FlexWrap.WRAP)
        layoutManager.setFlexDirection(FlexDirection.ROW)
        layoutManager.setJustifyContent(JustifyContent.FLEX_START)
        layoutManager.setAlignItems(AlignItems.FLEX_START)

        val adapter = TagAdapter(tags)
        tagRecyclerView.adapter = adapter
        tagRecyclerView.layoutManager = layoutManager
Run Code Online (Sandbox Code Playgroud)

(我试图设置layoutManager.setAlignItems(AlignItems.FLEX_START)layoutManager.setAlignItems(AlignItems.CENTER)然而它没有用...

android android-layout android-recyclerview android-flexboxlayout

11
推荐指数
1
解决办法
2371
查看次数

无法访问ActivityCompatApi23类

我的gradle文件存在运行时问题.我将此compile 'com.google.android:flexbox:0.3.1'作为编译时依赖项添加到我的Gradle文件中.我遇到了一个错误,并将其添加到我的项目级Gradle文件中.

maven {
            url "https://maven.google.com"
        }
Run Code Online (Sandbox Code Playgroud)

添加上述内容后,最终看起来很喜欢这个

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的应用程序级别Gradle文件中添加上述内容后,当我尝试运行我的应用程序时,我现在遇到了不同的错误.所以我按照SO的一些答案做了以下几点.

  1. 试过清洁和重建.
  2. 导航到路径projectName\.idea\libraries并删除包含除当前版本25.3.1 3 之外的支持库版本的文件.为了解决错误,我从我的应用程序级Gradle文件中进一步删除了该行,

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{exclude group:'com.android.support',module:'support-annotations'})

现在,最终的Gradle文件看起来像这样,带有错误,

错误:

Error:(28, 8) error: cannot access ActivityCompatApi23
class file for android.support.v4.app.ActivityCompatApi23 not found
Run Code Online (Sandbox Code Playgroud)

我的Gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false …
Run Code Online (Sandbox Code Playgroud)

android gradle android-build android-gradle-plugin android-flexboxlayout

8
推荐指数
2
解决办法
9681
查看次数

具有动态项目高度的水平 RecyclerView

我正在尝试实现RecyclerView水平滚动的 a,所以我使用的是LinearLayoutManager水平方向的 a。问题是我正在使用 2 种不同类型的项目填充 RecyclerView,具有不同的高度。这是我用于该项目的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp">

<LinearLayout
    android:id="@+id/document_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/ic_rounded"
    android:backgroundTint="@color/ms_black_ms_gray"
    android:gravity="center"
    android:layout_gravity="bottom"
    android:padding="5dp"
    android:paddingStart="15dp">

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:textSize="13sp"
        android:singleLine="true"
        android:maxWidth="80dp"
        tools:text="example_form"/>

    <TextView
        android:id="@+id/format"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:textSize="13sp" />

    …
</LinearLayout>

<android.support.v7.widget.CardView
    android:id="@+id/image_view"
    android:layout_width="120dp"
    android:layout_height="80dp"
    android:layout_gravity="bottom"
    app:cardCornerRadius="25dp"
    app:cardElevation="0dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/preview_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"/>

        …

    </RelativeLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

这是包含 的布局,RecyclerView基本上是这样的:

在此处输入图片说明

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingStart="14dp"
        android:paddingEnd="14dp">

        <ImageView
            android:id="@+id/attach"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android horizontal-scrolling android-recyclerview android-flexboxlayout

7
推荐指数
2
解决办法
1751
查看次数

当 FlexBoxLayoutManger 设置为 RecyclerView 的 layoutManager 时,如何计算行数

我正在使用FlexboxLayoutManager

FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(this);
recyclerView.setLayoutManager(flexboxLayoutManager);
Run Code Online (Sandbox Code Playgroud)

现在我必须增加项目recyclerView,如果项目数量超过 2 行,那么我必须显示“显示更多”选项作为第二行本身的最后一个项目。我怎样才能做到这一点?

每行包含不同数量的项目,即列可能因项目长度而异,这就是使用 FlexBoxLayoutManager 的原因。

android android-recyclerview android-flexboxlayout

5
推荐指数
1
解决办法
867
查看次数

java.lang.NoClassDefFoundError:使用FlexboxLayout时的androidx/core/view/ViewCompat

我正在使用 FlexboxLayout

下面加依存性build.gradleFlexboxLayout

dependencies {
    implementation 'com.google.android:flexbox:1.1.0'
}
Run Code Online (Sandbox Code Playgroud)

myLayout

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.flexbox.FlexboxLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">



</com.google.android.flexbox.FlexboxLayout>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误错误Scre​​enShot

java.lang.NoClassDefFoundError: androidx/core/view/ViewCompat
    at com.google.android.flexbox.FlexboxLayout.onLayout_Original(FlexboxLayout.java:565)
    at com.google.android.flexbox.FlexboxLayout.onLayout(FlexboxLayout.java)
    at android.view.View.layout_Original(View.java:20672)
    at android.view.View_Delegate.layout(View_Delegate.java:91)
    at android.view.View.layout(View.java:20658)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
    at android.view.View.layout_Original(View.java:20672)
    at android.view.View_Delegate.layout(View_Delegate.java:91)
    at android.view.View.layout(View.java:20658)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.support.v7.widget.ActionBarOverlayLayout.onLayout_Original(ActionBarOverlayLayout.java:444)
    at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java)
    at android.view.View.layout_Original(View.java:20672)
    at android.view.View_Delegate.layout(View_Delegate.java:91)
    at android.view.View.layout(View.java:20658)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
    at android.view.View.layout_Original(View.java:20672)
    at android.view.View_Delegate.layout(View_Delegate.java:91)
    at android.view.View.layout(View.java:20658)
    at android.view.ViewGroup.layout(ViewGroup.java:6194)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:348)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:386)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:450)
    at …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-flexboxlayout

5
推荐指数
1
解决办法
2144
查看次数

FlexboxLayout - 在第二行末尾显示标签或芯片或标签计数 android

我正在使用FlexboxLayout在 android 中显示芯片,但卡在 UI 中,我想在第二行末尾显示芯片数量,如下图所示在此输入图像描述

根据上面的设计,我想显示芯片直到第二行,并且不适合第二行的芯片应该增加芯片末尾的芯片数量

我检查的是

1- FlexboxLayout setMaxLine(2); 但在这种情况下,UI 只有两条线绘制,第二条线是拉伸

2- FlexboxLayout getFlexLineInternel() - 此 API 给出错误的结果。在行中添加 1 个项目后,行数会增加,然后给出getFlexLineInternel().size() == 2 这意味着视图已添加到第三行中,但我只想限制在 2 行中。

3-尝试使用材料芯片和芯片组-它没有给我在芯片组中绘制的线条数

4- 尝试使用类似于 ChipGroup 的Flowlayout 。没有给我按布局绘制的行数,以便我可以在第二行末尾显示计数

请给我建议什么对我的情况有帮助

这是我的代码

活动搜索标签.xml

<com.google.android.flexbox.FlexboxLayout
      android:id="@+id/assetLabelsContainer"
      android:layout_width="match_parent"
      android:layout_marginLeft="@dimen/size_16"
      android:layout_marginRight="@dimen/size_16"
      android:layout_height="wrap_content"
      app:flexWrap="wrap"/>
Run Code Online (Sandbox Code Playgroud)

LabelSearchActivity.java

   public class LabelSearchActivity extends SearchActivity {

  @BindView(R.id.assetLabelsContainer)
  public FlexboxLayout assetLabelsContainer;

  private int COUNTER_LABEL_ID = -1;
  private ArrayList<LabelModelParcelableItem> selectedLabels;
  private ArrayList<LabelModelParcelableItem> visibleSelectedList;
  private CompositeDisposable disposables;

  @Override
  protected void onCreate(Bundle savedInstanceState) { …
Run Code Online (Sandbox Code Playgroud)

android flowlayout material-design android-chips android-flexboxlayout

5
推荐指数
1
解决办法
1273
查看次数

以编程方式设置 FlexboxLayout 的属性 layout_wrapbefore

flexbox-layout包含TextView具有以下属性的内容:

app:layout_wrapBefore="true" 
Run Code Online (Sandbox Code Playgroud)

但我需要以false编程方式将其设置为!

关于如何做到这一点的任何想法?


xml,如果需要的话!

<com.google.android.flexbox.FlexboxLayout
        android:id="@+id/flexboxlayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        app:alignContent="stretch"
        app:alignItems="stretch"
        app:flexWrap="wrap"
        app:justifyContent="flex_end">


        <TextView
            android:id="@+id/mainText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:text="07:22 PM"
            android:textSize="12sp"
            app:layout_alignSelf="center"
            app:layout_wrapBefore="true" />

    </com.google.android.flexbox.FlexboxLayout>
Run Code Online (Sandbox Code Playgroud)

android android-flexboxlayout

4
推荐指数
1
解决办法
1363
查看次数

带 FlexboxLayoutManager 的交错布局

我有什么方法可以使用与此类似的 google Flexbox 库来实现交错布局

使用 StaggeredLayoutManager 实现的布局

上面的布局是使用创建的 StaggeredLayoutManger还保持图像的纵横比的

我试过代码:

recyclerView.apply {
        layoutManager = FlexboxLayoutManager(context).apply {
            flexWrap = FlexWrap.WRAP
            justifyContent = JustifyContent.CENTER
        }
        adapter = mAdapter
    }
Run Code Online (Sandbox Code Playgroud)

但它使单列布局和纵横比也没有保持(考虑到图像尺寸较大)。

android kotlin staggered-gridview android-flexboxlayout

4
推荐指数
1
解决办法
3992
查看次数

Flexboxlayout 以编程方式设置项目之间的间距

我有这个 Flexboxlayout 定义(官方 Google 库):

<com.google.android.flexbox.FlexboxLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:dividerDrawableHorizontal="@drawable/flexboxlayout_divider"
    app:flexWrap="wrap"
    app:justifyContent="space_between"
    app:showDividerHorizontal="middle">
Run Code Online (Sandbox Code Playgroud)

现在我想以编程方式创建相同的内容:

FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(activity);
flexboxLayoutManager.setFlexDirection(FlexDirection.COLUMN);
flexboxLayoutManager.setJustifyContent(JustifyContent.SPACE_BETWEEN);
flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
myRecyclerView.setLayoutManager(flexboxLayoutManager);
Run Code Online (Sandbox Code Playgroud)

我缺少的是app:dividerDrawableHorizontalapp:showDividerHorizontal属性,并且没有找到任何方法来设置它们。

android android-layout android-recyclerview android-flexboxlayout

4
推荐指数
1
解决办法
9814
查看次数

在 FlexboxLayout 中换行

我正在使用 FlexboxLayout 添加一些 EditText。每个 EditText 只包含 1 个字符的单词。我也使用 editText 作为空格,但保持它不可见。我使用布局设置 FlexWrap 作为“换行”。例如,如果我有两个单词,则第二个单词的某些字母会转到下一行。但是,我希望下一个单词(一组editText)转到下一行,而不仅仅是最后几个字母(editText)。

有没有办法对这些编辑文本进行分组并使整个单词转到下一行。或者有什么方法可以在程序本身内换行。我尝试将“EditText”添加到线性布局并将其添加到“FlexboxLayout”,但没有奏效。

android android-edittext android-flexboxlayout

2
推荐指数
1
解决办法
1197
查看次数

如何让FlexboxLayout滚动?

我在我的一项活动中使用 Android FlexboxLayout,但是当内容大于我的屏幕时,我无法滚动到那里查看它。所有示例似乎都是默认滚动的,但在我的代码中却没有这样做。

XML 是这样的:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.flexbox.FlexboxLayout
    android:id="@+id/fbRoot"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:alignContent="flex_start"
    app:alignItems="stretch"
    app:flexWrap="wrap">

    .. a lot of other views ..

</com.google.android.flexbox.FlexboxLayout>
Run Code Online (Sandbox Code Playgroud)

android android-flexboxlayout

2
推荐指数
1
解决办法
2589
查看次数

动态将 LayoutManager 更改为 FlexboxLayoutManager 时崩溃

我必须同时使用两者LinearLayoutManagerFlexbotLayoutManager取决于 RecyclerView 中孩子的大小。

当我更改LinearLayoutManagerFlexbotLayoutManager动态时:

recyclerView.layoutManager = 
            FlexibleFlexboxLayoutManager(context).apply {
                    flexWrap = FlexWrap.NOWRAP
                    flexDirection = FlexDirection.ROW
            }
Run Code Online (Sandbox Code Playgroud)

我面临这个错误:

java.lang.ClassCastException: android.support.v7.widget.RecyclerView$LayoutParams 无法转换为 com.google.android.flexbox.FlexItem at com.google.android.flexbox.FlexboxHelper.calculateFlexLines(FlexboxHelper.java:439) at com.google.android.flexbox.FlexboxHelper.calculateHorizo​​ntalFlexLines(FlexboxHelper.java:243) 在 com.google.android.flexbox.FlexboxLayoutManager.updateFlexLines(FlexboxLayoutManager.java:955) 在 com.google.android.flexbox.FlexboxLayoutManager.onLayoutChildren( FlexboxLayoutManager.java:731) 在 android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924) 在 android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3336) 在 android.view.View .measure(View.java:22071)

如何解决?

android android-flexboxlayout

0
推荐指数
1
解决办法
971
查看次数

如何在 flexbox 中居中“TextView”?

我尝试在 FlexboxLayout 中居中文本。我使用这个库 com.google.android:flexbox:0.2.5。我在列中有几个文本。我尝试了很多方法将它们放在该列的中间,但没有成功。

<com.google.android.flexbox.FlexboxLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            style="?metaButtonBarStyle"
            android:layout_width="77dp"
            android:layout_height="match_parent"
            android:background="@drawable/bg_pattern_dark_bitmap"
            android:orientation="vertical"
            android:alpha="1"
            app:flexWrap="wrap"
            app:justifyContent="space_between"
            >

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="lol"
                />
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="lol"
                />
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="lol"
                />
    </com.google.android.flexbox.FlexboxLayout>
Run Code Online (Sandbox Code Playgroud)

感谢您的任何帮助

xml android android-flexboxlayout

0
推荐指数
1
解决办法
1371
查看次数