简体   繁体   中英

Android layout_below refuses to work with CheckBox

I have the following RelativeLayout .

<?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="fill_parent">

    <TextView
            android="@+id/welcome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:paddingTop="20dp"
            android:text="@string/main" />
    <CheckBox
            android:id="@+id/startupopt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/welcome"
            android:layout_centerHorizontal="true"
            android:text="@string/startup"
            android:onClick="checkboxClicked">
    </CheckBox>
    <ImageView
            android:id="@+id/toggle_image"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_centerInParent="true" />

</RelativeLayout>

I'm trying to place the CheckBox below the TextView using layout_below attribute but it's not applying. The layout_centerHorizontal attrubute has an effect though. I think there is nothing wrong with the code but maybe there is. Could you please point out what's wrong?

in your TextBox you have this

android="@+id/welcome"

you need this

android:id="@+id/welcome"

and in your CheckBox you need to use

android:layout_below="@+id/welcome"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM