Ich möchte PercentRelativeLayout
während meiner Projekte verwenden, und dies erfolgreich mit Ansichten, die kein Bildlauf erfordern. Bei Verwendung von ScrollView's
funktionieren jedoch Attribute wie layout_heightPercent
und layout_marginTopPercent
nicht.Wie Verwenden von PercentRelativeLayout in einem CollapsingToolbarLayout?
Mein Problem ist speziell, wenn ich eine CollapsingToolbarLayout
und eine NestedScrollView
verwende. Ich habe einige Hinweise gefunden, warum dies nicht wie gewünscht funktioniert here.
Eine solution (zweite Antwort) auf die Frage ist, die ScrollView
zu erweitern und überschreiben die OnMeasure-Methode. Ich habe versucht, dies mit mehreren Ansichten zu machen, war aber nicht erfolgreich.
Hier ist der Plan Ich brauche Arbeit zu bekommen:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sign_in_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:fitsSystemWindows="true"
android:animateLayoutChanges="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/sign_in_app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:animateLayoutChanges="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/sign_in_collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:animateLayoutChanges="true"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:contentScrim="@color/primaryBackground"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="50%"
app:layout_heightPercent="80%"
app:layout_marginLeftPercent="33%"
android:scaleType="centerCrop"
android:src="@drawable/picture"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
</android.support.percent.PercentRelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="58dp"
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_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:animateLayoutChanges="true"
app:behavior_overlapTop="315dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_widthPercent="50%"
app:layout_heightPercent="80%"
app:layout_marginLeftPercent="33%"
android:scaleType="centerCrop"
android:src="@drawable/picture"
android:fitsSystemWindows="true" />
</android.support.percent.PercentRelativeLayout>
</android.support.v4.widget.NestedScrollView>
Jede Hilfe würde geschätzt.