简体   繁体   中英

android:layout_below with ImageView not working

Do android:layout_... s work with ImageView s? From the picture you can see that all 10 rows are on top of each other so that means that q2Image is not accepting the code android:layout_below="@/q1Image" for it to drop down a line and star the next row.

Am I just missing something or am I trying to do something that is impossible?

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="65"
    android:fillViewport="true" >

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

        <ImageView 
            android:id="@+id/q1Image"
            android:layout_width="10dp"
            android:layout_height="10dp"  /> 

        <TextView 
            android:id="@+id/q1Question"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/q1Image" /> 

        <TextView 
            android:id="@+id/q1Answer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"   
            android:layout_toRightOf="@id/q1Question"  /> 

        <TextView 
            android:id="@+id/q1Verse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"   
            android:layout_toRightOf="@id/q1Answer"  /> 

        <View 
            android:layout_width="fill_parent"
            android:layout_height="1dp"       
            android:background="#C2BEBF" />

        <ImageView 
            android:id="@+id/q2Image"
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:layout_below="@id/q1Image"  />

        <TextView 
            android:id="@+id/q2Question"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/q2Image" /> 

        <TextView 
            android:id="@+id/q2Answer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"   
            android:layout_toRightOf="@id/q2Question"  /> 

        <TextView 
            android:id="@+id/q2Verse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"   
            android:layout_toRightOf="@id/q2Answer"  /> 

        <View 
            android:layout_width="fill_parent"
            android:layout_height="1dp"       
            android:background="#C2BEBF" />
//Above code is first 2 rows.  There are 10 rows total but I removed the code for rows 3-10 for this post.

在此处输入图片说明

Try to put + between @ and id and everything must be ok

@+id

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <!-- here the columns -->
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <!-- here the columns -->
    </LinearLayout>
    .
    .

</LinearLayout>

Referencing Id's like that not always working. Replace "@id" with "@+id" everywhere. Example:

android:layout_below="@+id/q1Image"

The way you are accessing the ids in the code is correct. "@+id" is used to declare the id. All references to it following the declaration should be "@id". Are you having the same problems with the TextViews also? I think you should set the layout_below property for the TextViews as well. Because I can see text is also overlapped in your UI. eg.,

<TextView 
        android:id="@+id/q2Question"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below = "@id/q1Question"
        android:layout_toRightOf="@id/q2Image" />

RelativeLayout will not place a view below another unless you specify layout_below for it. Hence your TextViews appear overlapped.

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