我想在 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]
最佳答案
在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/