android:layout_below与ImageView无法正常工作

时间:2013-02-08 13:47:45

标签: java android layout imageview

android:layout_...ImageView合作吗?从图片中可以看出,所有10行都在彼此之上,这意味着q2Image不接受代码android:layout_below="@/q1Image",因为它下拉一行并为下一行加注星标。

我只是遗漏了一些东西,还是我想做一些不可能的事情?

<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.

enter image description here

3 个答案:

答案 0 :(得分:1)

尝试在@和id之间放置+,一切都一定正常

@+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>

答案 1 :(得分:0)

引用ID并不总是有效。到处都用“@ + id”替换“@id”。 例如:

android:layout_below="@+id/q1Image"

答案 2 :(得分:0)

您访问代码中的ID的方式是正确的。 “@ + id”用于声明id。声明后对它的所有引用都应为“@id”。您是否也遇到了与TextView相同的问题?我认为你也应该为TextViews设置layout_below属性。因为我可以看到文本在UI中也是重叠的。例如,

<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" />

除非您为其指定layout_below,否则RelativeLayout不会将视图放在另一个视图下方。因此,TextViews显示重叠。