在FlexboxLayout中有效显示许多视图

问题描述 投票:0回答:1

我的目标是在FlexboxLayout(或类似的东西)中有效地显示很多TextView(带有背景)。

我想以一种“标签”布局的方式显示电影中的演员和剧组成员的信息

How the layout looks like (one of the FlexboxLayouts is marked)

我通过LayoutInflater将TextViews [[动态地]膨胀]到FlexboxLayout中。 问题当然是由于大量数据(意味着很多视图,有时在20多个Flexbox布局中有30个或更多),片段/活动的创建时间增加了,而< [激活需要更长的时间才能打开。我要充气的TextView:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tag_name" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_margin="5dp" android:paddingStart="10dp" android:paddingEnd="10dp" android:gravity="center_vertical" android:background="@drawable/bg_tag" android:textColor="?android:textColorSecondary" android:text="@string/placeholder" />

我的容器布局(TextViews膨胀到FlexboxLayout @+id/fxl_names中:]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
  android:orientation="vertical">

  <TextView
    android:id="@+id/txt_names"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="?attr/colorOnBackground"
    android:padding="5dp"
    android:textSize="16sp"
    android:textStyle="bold"
    android:text="test" />

  //TextViews get inflated into this FlexboxLayout

  <com.google.android.flexbox.FlexboxLayout
    android:id="@+id/fxl_names"
    app:flexWrap="wrap"
    android:animateLayoutChanges="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

  <com.google.android.material.button.MaterialButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/view_more"
    android:visibility="gone"
    android:layout_margin="0dp"
    android:text="Show all"
    style="@style/Widget.MaterialComponents.Button.TextButton.Dialog" />

</LinearLayout>

感谢您提供有关优化此布局的帮助/建议!

我的目标是在FlexboxLayout(或类似的东西)中有效地显示很多TextView(带有背景)。我想以某种...
android layout layout-inflater android-flexboxlayout layout-optimization
1个回答
0
投票
对于您的问题,您可能不得不使用RecyclerView而不是FlexBoxLayout,这是我认为的最佳解决方案。还有FlexBoxLayoutManager来组织您的视图。
© www.soinside.com 2019 - 2024. All rights reserved.