0

さて、私は現在 TableLayout を使用してアクティビティのレイアウトに取り組んでおり、必要な場所にテーブルを取得しても、実際にはうまく機能していません。

現在の様子のスクリーンショットは次のとおりです。 ここに画像の説明を入力

現時点での目標は次の 3 つです。

  1. EditText と ToggleButton を含む LinearLayout を画面の水平方向の中央に配置します (まだそれもできていません)。

  2. テーブル レイアウト (trig ftns を含む 6 つのボタン) を、3 つの LinearLayouts に分割することなく、LL の下で水平方向に中央に配置します。

  3. マージンとパディング以外の絶対値を使用せずに、ボタンをすべて同じサイズにします。

上記の目標の一部またはすべてをどのように行うかについての洞察は、基本的に自分のxmlレイアウトの知識を使い果たし、この種の状況で通常行うことをプログラムで行うことを避けたいため、高く評価されます。

参考までに、上記の現在のレイアウトの xml を次に示します (xml バージョンの行ありますが、この投稿ではコピーしたくないだけです)。

<com.hinodesoftworks.lordkat.widgets.TitleBar
    android:id="@+id/calc_titlebar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/calc_input_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal" >

    <EditText
        android:id="@+id/calc_input"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/txt_trig_hint" />

    <ToggleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:background="@drawable/button_selector"
        android:paddingBottom="5dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="5dp"
        android:textOff="@string/txt_trig_toggle_radians"
        android:textOn="@string/txt_trig_toggle_degrees" />
</LinearLayout>

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:weightSum="3" >

    <TableRow
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" >

        <Button
            android:id="@+id/trig_sine_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="2dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="2dp"
            android:background="@drawable/button_selector"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp"
            android:text="@string/txt_trig_sine_button" />

        <Button
            android:id="@+id/trig_secant_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="2dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="2dp"
            android:background="@drawable/button_selector"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp"
            android:text="@string/txt_trig_secant_button" />
    </TableRow>

    <TableRow
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" >

        <Button
            android:id="@+id/trig_cosine_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="2dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="2dp"
            android:background="@drawable/button_selector"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp"
            android:text="@string/txt_trig_cosine_button" />

        <Button
            android:id="@+id/trig_cosecant_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="2dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="2dp"
            android:background="@drawable/button_selector"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp"
            android:text="@string/txt_trig_cosecant_button" />
    </TableRow>

    <TableRow
        android:layout_gravity="center_horizontal"
        android:layout_weight="1" >

        <Button
            android:id="@+id/trig_tangent_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="2dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="2dp"
            android:background="@drawable/button_selector"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp"
            android:text="@string/txt_trig_tangent_button" />

        <Button
            android:id="@+id/trig_cotangent_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="2dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="1dp"
            android:layout_marginTop="2dp"
            android:background="@drawable/button_selector"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp"
            android:text="@string/txt_trig_cotangent_button" />
    </TableRow>
</TableLayout>

<TextView
    android:id="@+id/calc_results_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/txt_trig_results_label" />

<TextView
    android:id="@+id/calc_results"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="123.456" />

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

4

2 に答える 2

1

1-) EditText と ToggleButton を画面の水平方向の中央に配置するには
、「android:layout_gravity="center_horizo​​ntal」の代わりに android:gravity="center_horizo​​ntal" を使用します。

2-) 回答(1)のように、テーブルを水平方向に中央に配置するには、「android:gravity="center_horizo​​ntal」を使用します

3-) マージンとパディング以外の絶対値を使用せずにすべてのボタンを同じサイズにするには、「android:stretchColumns="0,1"」を使用して列 0 と 1 をストレッチします。この属性を使用すると、絶対値を使用する必要はありません。したがって、結果のコードは次のようになります。

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:stretchColumns="0,1"
   >

<TableRow>
    <Button
        android:id="@+id/trig_sine_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher"
        android:text="txt_trig_sine_button" />
    <Button
        android:id="@+id/trig_secant_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher"
        android:text="txt_trig_secant_button" />
</TableRow>

....

于 2012-05-27T18:47:11.463 に答える
0

GridLayout を使用してみてください。メモリ効率が高く、ネストされたコンテナーがなく、このタイプのグリッドのようなデザインに最適です。

于 2013-06-01T23:52:29.470 に答える