0

私のテストAndroidアプリで2×2グリッド(縦1本、横1本)を実現するネストされた線形レイアウトがありますが、 。現在、私は手動で高さを任意の数(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はビデオを再生する責任があります。私は簡単なテストでグリッドレイアウトを使用していたときにビデオが再生されませんでした –

関連する問題