1

画面の上部に同じサイズの外側の正方形を5つ並べて作成します。各外側の正方形には、各外側の正方形の上部に、同じサイズの3つの小さな正方形を並べて含める必要があります。3つの小さな正方形のそれぞれがTextViewsです。

外側の正方形と内側の正方形にはそれぞれ境界線が必要です。これを使用して各正方形を区別します。これにより、ユーザーには、外側の正方形が5つ、内側の正方形が3つあることがわかります。

layout_width="0dp"とlayout_weight="2"を指定して、5つの別々のTableLayoutを宣言することにより、5つの同じサイズの外側の正方形を取得することができました。これらの各TableLayout内で、3つのTextViewを使用して単一の要素を定義します。

TextViewsを含む3つの内側の正方形のそれぞれを、画面サイズに関係なく同じサイズにするにはどうすればよいですか?各TextViewのlayout_weightを「.3」に設定しようとしましたが、これではうまくいきません。

TextViewsで3つの同じサイズの正方形を取得できる唯一の方法は、3つのミニ正方形のそれぞれにandroid:minWidth = "12dp"(または12dp以外の他の数値)を設定することですが、これは明らかに異なる場合には機能しませんサイズの画面。

私のテーブルはそれぞれ、以下のTableLayoutのように設定されています。私が含めたこのレイアウトは、ミニスクエアを正しく作成できるレイアウトですが、さまざまなサイズの画面では機能しません。余白を使用して、TextViews(黒い背景と白い輪郭)の周囲に実際に境界線を作成しました。

このレイアウトの他に、Shapeリソースを作成し、3つの小さな正方形の背景をそのShapeに設定しようとしましたが、それも機能しませんでしたが、そのリソースも含めました。

<TableLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#FFFFFF">

<TableRow android:background="#FFFFFF">
    <TextView 
        android:background="#000000"
        android:layout_marginLeft="1dip" 
        android:layout_marginRight="1dip" 
        android:layout_marginBottom="1dip"
        android:minWidth="12dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView 
        android:background="#000000"
        android:layout_marginLeft="1dip" 
        android:layout_marginRight="1dip" 
        android:layout_marginBottom="1dip"
        android:minWidth="12dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView 
        android:background="#000000"
        android:layout_marginLeft="1dip" 
        android:layout_marginBottom="1dip"
        android:layout_marginRight="1dip"
        android:minWidth="12dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</TableRow>

</TableLayout>

私が試したShapeリソースは次のとおりです。

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="#000000"/>
    <stroke android:width="1dp" color="#000000"/>
    <corners android:radius="1dp"/>
    <padding android:left="2dp" android:top="1dp"
        android:right="2dp" android:bottom="1dp" />
</shape>
4

0 に答える 0