Android:使用RelativeLayout将两个切换按钮放在另一个下面的问题

时间:2011-06-09 02:20:29

标签: android user-interface button toggle relativelayout

我对Toggle Buttons有一个奇怪的问题。我想水平居中,然后使用相对布局将它们放在另一个下面。

然而无论我做什么 - 他们总是并排结束

任何想法?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg7"
xmlns:android="http://schemas.android.com/apk/res/android">

<TextView android:id="@+id/spacer"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:text=" ">
</TextView>


<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/spacer"
    android:paddingTop="5dip"
    android:paddingBottom="10dip"
    android:gravity="center">

    <ToggleButton android:id="@+id/ShowNotification"
            android:onClick="switchNotification"
            android:textOn="Show Notification"
            android:layout_width="220dip"
            android:layout_height="50dip"
            android:layout_above="@+id/UpdateLog"
            android:textOff="No Notification"/>

    <ToggleButton android:id="@+id/UpdateLog"
            android:layout_width="220dip"
            android:layout_height="50dip"
            android:onClick="swtichLogging"
            android:textOn="Log"
            android:textOff="Don't Log"/>
</TableRow>
    </RelativeLayout>

提前致谢

2 个答案:

答案 0 :(得分:2)

我很确定它是因为你有一个TableRow不在TableLayout里面你想用间隔物做什么?改为使用填充或边距。据我所知,这就是你的代码看起来的样子:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg7"
    android:layout_margintop="65dp"
    >
    <ToggleButton android:id="@+id/ShowNotification"
        android:onClick="switchNotification"
        android:textOn="Show Notification"
        android:layout_width="220dip"
        android:layout_height="50dip"
        android:textOff="No Notification"
        android:layout_centerHorizontal="true"
        />
    <ToggleButton
        android:id="@+id/UpdateLog"
        android:layout_width="220dip"
        android:layout_height="50dip"
        android:onClick="swtichLogging"
        android:textOn="Log"
        android:textOff="Don't Log"
        android:below="@id/ShowNotification"
        android:layout_centerHorizontal="true"
        />
</RelativeLayout>

答案 1 :(得分:0)

尝试将每个按钮设置为FILL_PARENT。

相关问题