0

2x2 그리드 (세로 1 개, 가로 1 개)를 얻기 위해 내 테스트 안드로이드 앱에 중첩 선형 레이아웃을 사용하고 있지만, 전체 셀을 균등하게 채우는 데 문제가 있습니다. . 현재 수동으로 높이를 임의의 숫자 (150dp)로 설정했습니다. 그것을 고치고 그리드 셀 사이의 높이와 너비를 균등하게 나누는 방법은 무엇입니까?높이와 너비를 균등하게 공유하기 위해 안드로이드의 중첩 선형 레이아웃

기본적으로 나는 (2x3, 3x3 등) 화면을 균등하게 공유 할 수있는 가능한 그리드를 원하십니까? 다음과 같이 내부 LinearLayout에 대한

<?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 (. 각 surfaceView가 비디오를 재생하는 책임이 좀 그리드 레이아웃을 사용하여 문제가 있었다) :이 작동

<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

이 작품! Grid Layout은 언제나 셀의 수를 바꿀 때 이상적입니다. 그러나 각 surfaceView는 비디오를 재생해야합니다. 빠른 테스트에서 격자 레이아웃을 사용할 때 비디오가 재생되지 않았습니다. –

관련 문제