0

この画像のようにXMLレイアウトを設計しました。

テーブルレイアウトの4つのボタン

画面に4つのボタンを均等に配置する必要がありますが、機能させるのに問題があります。考えられるすべての変更を試しました。以下は、レイアウトのXMLです。

<RelativeLayout  
   android:layout_width="fill_parent"  
   android:layout_height="40dp" 
   android:id="@+id/buttonlayout"
   android:layout_alignBottom="@id/framelayout">


<TableLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android">

<TableRow>

  <Button
    android:id="@+id/previous"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/previous_icon" />

 <Button
    android:id="@+id/button_startprint"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/print_icon"
    android:padding="10dp" />

<Button
    android:id="@+id/button_cam"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/cam_icon"
    android:padding="10dp" />

<Button
    android:id="@+id/next"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/next_icon"
    android:hapticFeedbackEnabled="true"/>

 </TableRow>  
 </TableLayout> 
</RelativeLayout> 

誰かがこれで私を助けることができますか?

4

7 に答える 7

1

を使用しandroid:layout_weight=1、を使用android:layout_width="0dp"して同じ重みのボタンを作成します。

たとえば、編集してボタンを次のように定義します

 <Button
        android:id="@+id/button_cam"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=1
        android:background="@drawable/cam_icon"
        android:padding="10dp" />
于 2012-06-01T11:52:58.303 に答える
1

TableRowはLinearLayoutのサブクラスであるため、4つのボタンすべてに属性android:weight = "1"を設定する場合は、適切な間隔で配置する必要があります。パフォーマンスを向上させるには、android:layout_width="0dp"も使用することをお勧めします。

于 2012-06-01T11:54:05.613 に答える
1

すべてのボタンの幅をに置き換えてlayout_width="0dp"追加してみてくださいlayout_weight="1"

画像が引き伸ばされるのを避けるために、9パッチ画像を使用してみてください

  <TableRow>

      <Button
        android:id="@+id/previous"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_menu_compass"
        android:layout_weight="1" />

     <Button
        android:id="@+id/button_startprint"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_menu_mylocation"
        android:padding="10dp" 
        android:layout_weight="1"/>

    <Button
        android:id="@+id/button_cam"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_menu_mapmode"
        android:padding="10dp"
        android:layout_weight="1" />

    <Button
        android:id="@+id/next"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_menu_about"
        android:hapticFeedbackEnabled="true"
        android:layout_weight="1"/>

 </TableRow> 
于 2012-06-01T12:02:59.977 に答える
1

こんにちはjxgnはこのコードを使用します:

<?xml version="1.0" encoding="UTF-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <Button
                android:id="@+id/previous"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <Button
                android:id="@+id/button_startprint"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <Button
                android:id="@+id/button_cam"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

            <Button
                android:id="@+id/next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>
    </TableRow>

</TableLayout>
于 2012-06-01T12:08:47.170 に答える
0

xmlに適用するandroid:layout_weight="1"と、ボタンの画像が引き伸ばされます。

ボタンの画像を引き伸ばしたくない場合は、ドローアブルを使用ImageButtonして設定してください。android:src

以下のコードを参照してください。

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow>

        <ImageButton
            android:id="@+id/previous"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/previous_icon"
            android:background="@android:color/transparent"
            android:layout_weight="1" />

        <ImageButton
            android:id="@+id/button_startprint"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/print_icon"
            android:background="@android:color/transparent"
            android:padding="10dp"
            android:layout_weight="1" />

        <ImageButton
            android:id="@+id/button_cam"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/cam_icon"
            android:background="@android:color/transparent"
            android:padding="10dp"
            android:layout_weight="1" />

        <ImageButton
            android:id="@+id/next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/next_icon"
            android:background="@android:color/transparent"
            android:hapticFeedbackEnabled="true"
            android:layout_weight="1" />
    </TableRow>
</TableLayout>

`

于 2012-06-01T12:15:35.190 に答える
0

各ボタンで設定してみてください:

android:layout_weight="0.25"

これがすでにあなたのために働くことを願っています

于 2012-06-01T11:55:19.503 に答える
0

これを試してみてくださいそれは便利です

  <RelativeLayout  
    xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"  
   android:layout_height="wrap_content" 
   android:id="@+id/buttonlayout"     >


<TableLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android">

<TableRow>

  <Button
    android:id="@+id/previous"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:background="@drawable/ic_launcher"  
    android:layout_weight="1"/>

 <Button
    android:id="@+id/button_startprint"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:background="@drawable/ic_launcher" 
    android:layout_weight="1"
    />

<Button
    android:id="@+id/button_cam"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_launcher" 
    android:layout_weight="1"     />

 <Button
    android:id="@+id/next"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
  android:background="@drawable/ic_launcher" 
    android:layout_weight="1"       />

  </TableRow>  
  </TableLayout> 
  </RelativeLayout> 
于 2012-06-01T11:58:52.117 に答える