2016-07-21 8 views
0

Ich habe eine Hauptaktivität Layout, die eine CollapsingToolbarLayout, in denen ich ein benutzerdefiniertes Layout/Ansicht habe. Ich habe dieses benutzerdefinierte Layout mit dem Tag 'include' zum CollapsingToolbar hinzugefügt. Es wird zwar angezeigt, aber das benutzerdefinierte Layout wurde nicht aktualisiert. Dieses:Aufblasen Layout referenziert von übergeordneten Layout mit 'Include' Tag

RelativeLayout r = (RelativeLayout) findViewById(R.id.create_quote_toolbar_layout); 
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v = inflater.inflate(R.layout.create_quote_toolbar, r, false); 
    TextView T = (TextView)v.findViewById(R.id.lineTotal); 
    T.setText("sdrsfLineTotal"); 

scheint nicht zu funktionieren.

main_activity_layout.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".CreateQuoteActivity" > 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" > 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="100dp" 
      app:expandedTitleMarginStart="48dp" > 

      <include layout="@layout/create_quote_toolbar"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:clipToPadding="false" > 

     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@android:id/list"/> 

    </android.support.v4.widget.NestedScrollView> 

</android.support.design.widget.CoordinatorLayout> 

custom_toolbar_layout.xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="400dp" 
    android:id="@+id/create_quote_toolbar_layout"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/deliverToAddress" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:textSize="16dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/phoneNumber" 
     android:layout_below="@+id/deliverToAddress" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:textSize="16dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/name" 
     android:layout_below="@+id/phoneNumber" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:textSize="16dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/date" 
     android:layout_below="@+id/name" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:textSize="16dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Valid Until:" 
     android:id="@+id/textView5" 
     android:layout_below="@+id/date" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginTop="13dp" 
     android:textSize="16dp"/> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/expirationDate" 
     android:layout_below="@+id/date" 
     android:layout_toRightOf="@+id/textView5" 
     android:layout_toEndOf="@+id/textView5" 
     android:hint="dd/mm/yyyy" 
     android:textSize="16dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/total" 
     android:layout_below="@+id/expirationDate" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:textSize="16dp"/> 

    <EditText 
     android:layout_width="200dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/itemDescription" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:hint="Item Description" 
     android:textSize="16dp"/> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/quantity" 
     android:layout_alignTop="@+id/itemDescription" 
     android:layout_toRightOf="@+id/itemDescription" 
     android:layout_toEndOf="@+id/itemDescription" 
     android:hint="Quantity" 
     android:textSize="16dp"/> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/unitPrice" 
     android:layout_below="@+id/quantity" 
     android:layout_toRightOf="@+id/itemDescription" 
     android:layout_toEndOf="@+id/itemDescription" 
     android:hint="Unit Price" 
     android:textSize="16dp"/> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/discount" 
     android:layout_below="@+id/unitPrice" 
     android:layout_alignLeft="@+id/unitPrice" 
     android:layout_alignStart="@+id/unitPrice" 
     android:hint="Discount" 
     android:textSize="16dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/lineTotal" 
     android:textSize="16dp" 
     android:layout_below="@+id/discount" 
     android:layout_alignRight="@+id/discount" 
     android:layout_alignEnd="@+id/discount"/> 

    <Button 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Add Item" 
     android:id="@+id/addItemButton" 
     android:layout_alignParentBottom="true" 
     android:layout_toLeftOf="@+id/expirationDate" 
     android:layout_toStartOf="@+id/expirationDate"/> 

    <Button 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Send Quote" 
     android:id="@+id/respondButton" 
     android:layout_alignParentBottom="true" 
     android:layout_alignRight="@+id/total" 
     android:layout_alignEnd="@+id/total"/> 

</RelativeLayout> 
+0

Warum möchten Sie es aufblasen? Was ist dein Ziel? – Divers

+0

Ich habe Knöpfe und andere Widgets, die ich brauche, um Zuhörer auf etc zu setzen ... im Grunde macht es funktioniert – BiGGZ

+0

Sie werden aufgeblasen, aber fügen Sie diese aufgeblähte Ansicht zur Ansicht Ihrer Aktivität als Unteransicht hinzu? –

Antwort

0

Wenn Sie die Stammansicht der Tätigkeit mit setContentView gesetzt haben es keinen Grund für Sie aufzublasen die Aussicht. Wenn Sie das Tag in der XML-Datei verwenden, bläht es automatisch die Ansicht auf, wenn Sie es in der Aktivität festlegen.

Wenn Sie eine Ansicht finden möchten, dann würden Sie einfach eine findViewById auf die ID wie normalerweise für die anderen IDs tun.

Zum Beispiel würden Sie in Ihrem onCreate Methode tun:

setContentView (R.layout.main_activity_layout)

Danach können Sie einfach tun

findViewById (create_quote_toolbar_layout)

Und Das wird das RelativeLayout in der von Ihnen eingeschlossenen Ansicht finden.

+0

"Wenn Sie die Stammansicht in der Aktivität mit setContentView festgelegt haben, gibt es keinen Grund, die Ansicht aufzublähen. Wenn Sie das Tag in der XML-Datei verwenden, bläht es automatisch die Ansicht auf, wenn Sie es in der Aktivität .... ". So einfach. Das war der Trick. – BiGGZ

Verwandte Themen