Das ist, was ich versuche zu erreichen: Benutzerdefinierte Verhalten nicht funktioniert (CoordinatorLayout)
Ich bemerkte die layoutDependsOn()
und onDependentViewChanged()
sind überhaupt nicht genannt habe.
Aus Gründen der Prüfung habe ich versucht, "Skalierung" statt "gesetzt XY" für das benutzerdefinierte Verhalten mit:
public class CustomBehavior extends CoordinatorLayout.Behavior<LinearLayout>
{
public CustomBehavior(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency)
{
return dependency instanceof LinearLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, View dependency)
{
float translationY = getTranslationY(parent, child);
float percentComplete = -translationY/dependency.getHeight();
float scaleFactor = 1 - percentComplete;
child.setScaleX(scaleFactor);
child.setScaleY(scaleFactor);
return false;
}
private float getTranslationY(CoordinatorLayout parent, LinearLayout child)
{
float minOffset = 0;
final List<View> dependencies = parent.getDependencies(child);
for (int i = 0, z = dependencies.size(); i < z; i++)
{
final View view = dependencies.get(i);
if (view instanceof LinearLayout && parent.doViewsOverlap(child, view))
{
minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - view.getHeight());
}
}
return minOffset;
}
}
Das ist aber das Fragment xml:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:id="@+id/myLinearLayout"
android:layout_width="330dp"
android:layout_marginTop="30dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical"
app:layout_behavior="com.test.CustomBehavior">
...
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/bottomSheetLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:behavior_peekHeight="100dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Hier ist Ihr Kind Relativayout und abhängige Ansicht ist LinearLayout richtig? –