gradle implementation 'com.android.support:design:version' <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_behavior="com.example.MyCustomBehavior" app:srcCompat="@drawable/image" /> </android.support.design.widget.CoordinatorLayout> public class MyCustomBehavior extends CoordinatorLayout.Behavior<ImageView> { @Override public boolean layoutDependsOn(CoordinatorLayout parent, ImageView child, View dependency) { return dependency instanceof TextView; } @Override public boolean onDependentViewChanged(CoordinatorLayout parent, ImageView child, View dependency) { child.setX(dependency.getX() + dependency.getWidth()); child.setY(dependency.getY() + dependency.getHeight() - child.getHeight()); return true; } }


上一篇:
下一篇:
切换中文