1

据我所知,@+id 和@id 的区别在于第一次创建资源id 并在不同的地方重用已经存在的资源id。例如,如果我们有一个相对布局,其中有两个 textView 在另一个下方,我们将使用 @resourceId 作为第二个 textView,它引用第一个 TextView。问题是,在将 android studio 更新到 3.0 后,@resourceId 不再工作。要将第二个 textView 放在第一个下面,我需要使用 @+firstTextViewId 而不是 @firstTextViewId。更具体地说,我需要使用,

android:layout_below="@+id/totalQty"

代替

android:layout_below="@id/totalQty"

这是代码

<RelativeLayout
    android:id="@+id/relBottomLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">
    <TextView
        android:id="@+id/totalQty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="abcdef"/>
    <TextView
        android:id="@+id/totalPrice"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/totalQty"
        android:text="saasdfdsdfsdf"/>

    <TextView
        android:id="@+id/totalNetPrice"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/totalPrice"
        android:text="abcdsadfsafddgfdgfgdef"
        />
</RelativeLayout>

是理解问题吗?或任何一端的问题?谁能解释一下?

4

1 回答 1

0
I just remove + sign at @+id from your code. Here's the updated code

<RelativeLayout android:id="@+id/relBottomLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView
        android:id="@+id/totalQty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="abcdef"/>
    <TextView
        android:id="@+id/totalPrice"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/totalQty"
        android:text="saasdfdsdfsdf"/>

    <TextView
        android:id="@+id/totalNetPrice"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/totalPrice"
        android:text="abcdsadfsafddgfdgfgdef"
        />
</RelativeLayout>
于 2017-12-01T09:27:50.380 回答