无法将Spinner放在Android XML中的ScrollView下面

时间:2015-01-15 04:08:47

标签: android xml

我的ScrollView包含TextViewSpinner。我想将ScrollView直接放在Spinner上方。但是,当我尝试运行项目时,我的代码给了我一个错误:

Error:(11, 31) No resource found that matches the given name (at 'layout_above' with value '@id/tense_spinner').

这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.wsandhu.conjugation.LearnActivity$PlaceholderFragment">

<ScrollView
    android:id="@+id/scrollview"
    android:layout_above="@id/tense_spinner"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<TextView android:text="Placeholder text"
    android:id="@+id/learn_textview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
</ScrollView>

<Spinner
    android:id="@+id/tense_spinner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />

</RelativeLayout>

有什么想法吗?

1 个答案:

答案 0 :(得分:4)

试试这个..

替换此行

android:layout_above="@id/tense_spinner"

通过这一行

android:layout_above="@+id/tense_spinner"

也请查看

Difference between "@id/" and "@+id/" in Android

修改

OR 使用线性布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="4"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.wsandhu.conjugation.LearnActivity$PlaceholderFragment" >

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3" >

        <TextView
            android:id="@+id/learn_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Placeholder text" />
    </ScrollView>

    <Spinner
        android:id="@+id/tense_spinner"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

</LinearLayout>