如何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
我的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的一些答案做了以下几点.
导航到路径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
我正在尝试实现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
我正在使用FlexboxLayoutManager:
FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(this);
recyclerView.setLayoutManager(flexboxLayoutManager);
Run Code Online (Sandbox Code Playgroud)
现在我必须增加项目recyclerView,如果项目数量超过 2 行,那么我必须显示“显示更多”选项作为第二行本身的最后一个项目。我怎样才能做到这一点?
每行包含不同数量的项目,即列可能因项目长度而异,这就是使用 FlexBoxLayoutManager 的原因。
我正在使用 FlexboxLayout
下面加依存性build.gradle的FlexboxLayout
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)
我收到以下错误错误ScreenShot
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) 我正在使用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
我 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) 我有什么方法可以使用与此类似的 google Flexbox 库来实现交错布局
上面的布局是使用创建的 StaggeredLayoutManger还保持图像的纵横比的
我试过代码:
recyclerView.apply {
layoutManager = FlexboxLayoutManager(context).apply {
flexWrap = FlexWrap.WRAP
justifyContent = JustifyContent.CENTER
}
adapter = mAdapter
}
Run Code Online (Sandbox Code Playgroud)
但它使单列布局和纵横比也没有保持(考虑到图像尺寸较大)。
我有这个 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:dividerDrawableHorizontal和app:showDividerHorizontal属性,并且没有找到任何方法来设置它们。
android android-layout android-recyclerview android-flexboxlayout
我正在使用 FlexboxLayout 添加一些 EditText。每个 EditText 只包含 1 个字符的单词。我也使用 editText 作为空格,但保持它不可见。我使用布局设置 FlexWrap 作为“换行”。例如,如果我有两个单词,则第二个单词的某些字母会转到下一行。但是,我希望下一个单词(一组editText)转到下一行,而不仅仅是最后几个字母(editText)。
有没有办法对这些编辑文本进行分组并使整个单词转到下一行。或者有什么方法可以在程序本身内换行。我尝试将“EditText”添加到线性布局并将其添加到“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) 我必须同时使用两者LinearLayoutManager或FlexbotLayoutManager取决于 RecyclerView 中孩子的大小。
当我更改LinearLayoutManager为FlexbotLayoutManager动态时:
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.calculateHorizontalFlexLines(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)
如何解决?
我尝试在 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)
感谢您的任何帮助