需要均匀间隔排的按钮

Joh*_*ore 2 xml android

使用3行和4列我尝试将所有按钮水平均匀地隔开,但都失败了.垂直很好.

下面是3个不同的尝试来分隔按钮,我的3行中的每一行都有1个.第一行拉伸图形(这是不需要的),第二行不拉伸但没有间距(图形之间需要间距),而第三行没有任何间距.请帮我把它们均匀分开.在同一网站上的其他人解决方案没有奏效.我应该尝试使用表吗?

视觉摘要=没有拉伸图形:我想要| xxxx | 而不是| xxxx |

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

<LinearLayout
    android:id="@+id/row1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>
</LinearLayout>

<LinearLayout
    android:id="@+id/row2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/row3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal"
    android:weightSum="1" >

    <Button
        android:id="@+id/c1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />
</LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Nim*_*ary 7

试试这个:

<LinearLayout
    android:id="@+id/row1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

试试你的第一行.同样可以对所有行进行,

因此,除非您不希望图像被拉伸,否则您需要在布局中说出它们.这样做你将管理间距,drawable看起来很好.如果拉伸按钮,则绘图也将相应拉伸.