如何构建android灵活的堆栈布局?

时间:2017-11-30 13:36:14

标签: android android-layout layout

我今天遇到的这个布局问题对我来说似乎不太容易。

这是:我的文本中间有一个应该修改的数字(例如:删除早于 10 天的记录)。我希望用户直接在文本中修改此号码。为此,我有TextView + EditText + TextView Layout 但是在较小的屏幕尺寸上,如果第二个TextView不适合,这可能是一场灾难。所以,我希望我的布局做这样的事情:enter image description here 通常,我希望行为在多行中分割时类似于文本行为。 我想我已经在其他地方看到过这种行为(堆栈布局或其他东西),但如何在原生Android应用程序中做到这一点?这有布局吗?

1 个答案:

答案 0 :(得分:2)

您可以将视图包装在flexbox布局

https://github.com/google/flexbox-layout

添加你的依赖

dependencies {
    compile 'com.google.android:flexbox:0.3.1'
}

<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"
  app:flexWrap="wrap"
  app:alignItems="stretch"
  app:alignContent="stretch" >

<TextView
    android:id="@+id/textview1"
    android:layout_width="120dp"
    android:layout_height="80dp"
    app:layout_flexBasisPercent="50%"
    />

<TextView
    android:id="@+id/textview2"
    android:layout_width="80dp"
    android:layout_height="80dp"
    app:layout_alignSelf="center"
    />

<TextView
    android:id="@+id/textview3"
    android:layout_width="160dp"
    android:layout_height="80dp"
    app:layout_alignSelf="flex_end"
    />
</com.google.android.flexbox.FlexboxLayout>
相关问题