【发布时间】:2016-10-26 09:07:49
【问题描述】:
我在我的测试 Android 应用程序中有一个嵌套线性布局,以实现 2x2 网格(一个垂直和一个水平),但我无法让单元格均匀地填充整个屏幕。目前我手动将高度设置为任意数字(150dp)。如何修复它并使网格单元之间的高度和宽度均匀分布?
基本上,我希望我拥有任意数量的可能网格(2x3、3x3 等)来均匀共享屏幕? (每个surfaceView负责播放视频。我在使用网格布局时遇到了一些问题)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearlayout_0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearlayout_10"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:orientation="horizontal" >
<SurfaceView
android:id="@+id/video_11_surfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<SurfaceView
android:id="@+id/video_12_surfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearlayout_11"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="horizontal" >
<SurfaceView
android:id="@+id/video_21_surfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<SurfaceView
android:id="@+id/video_22_surfaceview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
我建议改用 GridLayout
-
每个surfaceView负责播放一个视频。我在使用网格布局时遇到了一些问题。
标签: android android-layout layout android-linearlayout surfaceview