2017-11-29 1 views
1

Soweit ich weiß, ist der Unterschied zwischen @ + ID und @id, eine Ressource-ID zum ersten Mal zu erstellen und die bereits vorhandene Ressourcen-ID an verschiedenen Orten wiederzuverwenden. Zum Beispiel, wenn wir ein Relatives Layout haben, das zwei textViews untereinander hat, verwenden wir @resourceId für das zweite textView, das auf das erste TextView verweist. Das Problem ist, nach der Aktualisierung des Android Studio auf 3.0, funktioniert @resourceId nicht mehr. Um zweiten TextView unter dem ersten zu platzieren, muss ich @ + firstTextViewId anstelle von @firstTextViewId verwenden. Genauer gesagt muss ich, der Code@id funktioniert nicht innerhalb des relativen Layouts

android:layout_below="@+id/totalQty" 

statt

android:layout_below="@id/totalQty" 

Hier verwenden ist

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

Ist es ein Verständnis Problem? oder ein Problem von irgendeinem Ende? Kann mir bitte jemand erklären?

+0

haben Sie versucht, Projekt – Bek

+0

zu reinigen und neu zu erstellen, was ist Ihre Wurzel Ihres Layouts? –

+1

Es ist möglich, dass die neueren Tools Dateien anders verarbeiten - nicht unbedingt von oben nach unten -, so dass es die '@ ID' vor der' @ + ID' trifft. Verwenden Sie einfach überall "@ + id". Es wird nichts tun. –

Antwort

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> 
Verwandte Themen