0

У меня есть вложенная линейная компоновка в моем тестовом приложении для Android, чтобы получить сетку 2x2 (одна вертикальная и одна горизонтальная), но у меня есть проблема, заключающаяся в том, что ячейки равномерно заполняют весь экран , В настоящее время я вручную устанавливаю высоту как произвольное число (150dp). Как я могу его исправить и равномерно распределить высоту и ширину между ячейками сетки?Вложенная линейная компоновка в Android для равномерного распределения высоты и ширины

В принципе, я хочу, чтобы любое количество возможной сетки у меня (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> 
+2

Я бы предложил использовать GridLayout вместо – SillyFidget

+0

Каждый объект surfaceView отвечает за воспроизведение видео. У меня были проблемы с использованием сетки. –

ответ

1

Набор layout_weight для внутренней LinearLayout следующим образом:

<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="0dp" 
    android:layout_weight="1" 
    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="0dp" 
    android:layout_weight="1" 
    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> 

Это работает, но вы можете посмотреть на GridLayout.

+0

Это работает! Макет сетки был бы идеальным, так как я изменю количество ячеек в любое время. Но каждый surfaceView отвечает за воспроизведение видео. Видео не воспроизводилось, когда я использовал макет сетки в быстром тесте –

 Смежные вопросы

  • Нет связанных вопросов^_^