java - Android 中的响应式布局

标签 java android xml

我想在 Android 中进行响应式设计,即我需要这样一种布局,我将在其中以编程方式添加 View ,它们将根据屏幕尺寸进行调整。 例如: 我想在布局中添加 10 个 View 当我添加它们时,如果每行只有三个 View ,那么它们会自动调整为四行三列,即

[0,0] [0,1] [0,2]

[1,0] [1,1] [1,2]

[2,0] [2,1] [2,2]

[3,0]

但与横向模式一样,垂直方向有更多空间

[0,0] [0,1] [0,2] [0,3] [0,4]

[1,0] [1,1] [1,2] [1,3] [1,4]

最佳答案

Use flexbox layout

builde.gradle中添加

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

并在布局 xml 中使用它。即

<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="wrap_content"
    app:alignItems="center"
    app:alignContent="center"
    app:flexDirection="row"
    app:flexWrap="wrap">

   ...
</com.google.android.flexbox.FlexboxLayout>

关于java - Android 中的响应式布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46055273/

相关文章:

java - 为什么portlet的renderRequest.setAttribute返回最后一个变量?

java - 使用 Android API 发布推文

xml - 如何将 XElements 嵌入到 VB.NET 中的 XML 文本中?

java - 从 EURID(EPP 协议(protocol))提供的 *.xsd 生成模型时出现 JAXB SAXParseException

java - 将对象序列化为 XML,无需 [xmlns =""]

java - 无法执行 hibernate 查询

java - 编码对象时未使用 MongoDB BSON 编解码器

java - 规范化数组是什么意思?

Android - firebase 云消息传递,一个 firebase 项目中的两个应用程序

android - 无法在 eclipse 中导入 android 支持库