0

我想创建两行

TextView .... CustomeSwitvchView

CustomeSwitchView ... TextView

但是,使用此 xml 不会产生预期的顺序。

两行仅显示右对齐的 CustomeSwitchView,没有显示文本。

    <LinearLayout style="@style/settingsSection">


        <RelativeLayout
            android:id="@+id/settingsSwitchLayoutRtl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                    style="@style/settingsSelection" android:background="@drawable/item_selector_single"
                android:id="@+id/settingsSwitchRtl" />

            <TextView
                android:id="@+id/switch_text"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@id/settingsSwitchRtl"
                android:layout_centerVertical="true"
                android:textColor="#00FF00"
                android:text="My Settings1" />
      </RelativeLayout>

        <RelativeLayout
             android:id="@+id/settingsSwitchLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                    style="@style/settingsSelection" android:background="@drawable/item_selector_single"
                    android:id="@+id/settingsSwitch" />


                <TextView
                android:id="@+id/switch_text"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/settingsSwitch"
                android:layout_centerVertical="true"
                android:textColor="#00FF00"
                android:text="My Settings2" />


        </RelativeLayout>

    </LinearLayout>

我怎样才能解决这个问题?

4

3 回答 3

0

尝试这个:

<LinearLayout style="@style/settingsSection">


        <RelativeLayout
            android:id="@+id/settingsSwitchLayoutRtl"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                    style="@style/settingsSelection" android:background="@drawable/item_selector_single"
                    android:layout_alignParentTop="true"
                android:id="@+id/settingsSwitchRtl" />

            <TextView
                android:id="@+id/switch_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@id/settingsSwitchRtl"
                android:layout_centerVertical="true"
                android:gravity="center_horizontal"
                android:textColor="#00FF00"
                android:text="My Settings1" />
      </RelativeLayout>

        <RelativeLayout
             android:id="@+id/settingsSwitchLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                    style="@style/settingsSelection" android:background="@drawable/item_selector_single"
                    android:id="@+id/settingsSwitch" />

            <TextView
                android:id="@+id/switch_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/settingsSwitch"
                android:layout_centerVertical="true"
                android:gravity="center_horizontal"
                android:textColor="#00FF00"
                android:text="My Settings2" />
        </RelativeLayout>

    </LinearLayout>
于 2013-11-12T10:28:33.753 回答
0

我不确定,但你可以试试

<LinearLayout style="@style/settingsSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation = "vertical">


        <RelativeLayout
            android:id="@+id/settingsSwitchLayoutRtl"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                    style="@style/settingsSelection" android:background="@drawable/item_selector_single"
                 android:layout_alignParentRight="true"
                android:id="@+id/settingsSwitchRtl" />

            <TextView
                android:id="@+id/switch_text"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@id/settingsSwitchRtl"
                android:layout_centerVertical="true"
                android:textColor="#00FF00"
                android:text="My Settings1" />
      </RelativeLayout>

        <RelativeLayout
             android:id="@+id/settingsSwitchLayout"
                android:layout_width="match_parent"
                android:layout_below="@+id/settingsSwitchLayoutRtl"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                    style="@style/settingsSelection" android:background="@drawable/item_selector_single"
                    android:layout_alignParentLeft="true"
                    android:id="@+id/settingsSwitch" />


                <TextView
                android:id="@+id/switch_text"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/settingsSwitch"
                android:layout_centerVertical="true"
                android:textColor="#00FF00"
                android:text="My Settings2" />


        </RelativeLayout>

    </LinearLayout>
于 2013-11-12T10:36:51.100 回答
0

尝试这个..

<LinearLayout style="@style/settingsSection">


        <RelativeLayout
            android:id="@+id/settingsSwitchLayoutRtl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                  style="@style/settingsSelection"
                  android:background="@drawable/item_selector_single"
                  android:layout_alignParentRight="true"
                  android:paddingLeft="85dp"
                  android:id="@+id/settingsSwitchRtl" />

            <TextView
                android:id="@+id/switch_text"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:textColor="#00FF00"
                android:text="My Settings1" />
      </RelativeLayout>

        <RelativeLayout
             android:id="@+id/settingsSwitchLayout"
                android:layout_width="wrap_content"
                android:layout_below="@+id/settingsSwitchLayoutRtl"
                android:layout_height="wrap_content">

            <com.me.settings.SettingsSwitchView
                    style="@style/settingsSelection" 
                    android:layout_alignParentLeft="true"
                    android:paddingRight="85dp"
                    android:background="@drawable/item_selector_single"
                    android:id="@+id/settingsSwitch" />


                <TextView
                android:id="@+id/switch_text"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"
                android:textColor="#00FF00"
                android:text="My Settings2" />


        </RelativeLayout>

    </LinearLayout>
于 2013-11-12T10:31:22.627 回答