So hier ist ein Code aus einem Udacity-Projekt für Material Design. Es soll eine kollabierende Symbolleiste zeigen, die von einem Foto mit Text in einfachen Text umgewandelt wird. Die Idacity-Videos lassen mich glauben, dass der Code funktioniert hat, aber als ich die App auf mein Handy heruntergeladen habe, ist die Symbolleiste nicht zusammengebrochen (das Betriebssystem ist Android 6.0.1, v23). Gibt es etwas, das ich ändern könnte, um sicherzustellen, dass die Symbolleiste kollabiert?Parallax Scrolling/Collapsable Toolbar in Android
Der Code
xml
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="192dp"
android:background="?colorPrimary">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
app:expandedTitleMarginStart="72dp"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax"
android:scaleType="centerCrop"
android:src="@drawable/eclairs" />
<android.support.v7.widget.Toolbar
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:navigationIcon="@drawable/arrow_left"
app:contentInsetStart="72dp"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="wrap_content">
<TextView
android:layout_marginTop="16dp"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"
android:text="@string/cupcake_ipsum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
</ScrollView>
JAVA
package com.example.android.dynamicsurfacesdemo;
import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout)).setTitle("Eclairs");
}
}
Können Sie einen Screenshot hochladen? – CaseyB
Ist das das komplette Layout XML? Das sollte alles in einem 'CoordinatorLayout' verpackt sein. –
die URL ist https://github.com/udacity/ud862-samples/tree/master/DynamicSurfacesDemo/app/src/main –