Android BottomSheet 覆盖了锚定 ImageView 的一半
Android BottomSheet covers half of anchored ImageView
我有一个 CoordinatorLayout
,其中我有一个 BottomSheet
和一个 ImageView
。
这是我的 BottomSheett:
<include layout="@layout/bottom_sheet_layout"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_hideable="false"
app:behavior_peekHeight="80dp"
app:layout_behavior="@string/bottom_sheet_behavior"/>
这是我的 ImageView:
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_location_crosshairs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
app:layout_anchorGravity="top|end"
app:layout_anchor="@id/bottom_sheet"
app:srcCompat="@drawable/my_svg_icon"/>
无论我的 XML 布局中的视图顺序如何,我总是得到相同的结果:我的 ImageView 很好地锚定到 bottomsheet,但锚点出现在我的图像的中心。
我想知道如何让我的图像底部而不是它的中心被锚定。
尝试应用任何类型的底边距只会让底页滑动直到到达图像中心,然后再使图像也滑动。
感谢您的帮助!
您可以创建一个空 View
,将 layout_height
和 layout_width
设置为 wrap_content
。
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
然后 link 这个空视图到 BottomSheet
。
我有一个 CoordinatorLayout
,其中我有一个 BottomSheet
和一个 ImageView
。
这是我的 BottomSheett:
<include layout="@layout/bottom_sheet_layout"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_hideable="false"
app:behavior_peekHeight="80dp"
app:layout_behavior="@string/bottom_sheet_behavior"/>
这是我的 ImageView:
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_location_crosshairs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
app:layout_anchorGravity="top|end"
app:layout_anchor="@id/bottom_sheet"
app:srcCompat="@drawable/my_svg_icon"/>
无论我的 XML 布局中的视图顺序如何,我总是得到相同的结果:我的 ImageView 很好地锚定到 bottomsheet,但锚点出现在我的图像的中心。
我想知道如何让我的图像底部而不是它的中心被锚定。 尝试应用任何类型的底边距只会让底页滑动直到到达图像中心,然后再使图像也滑动。
感谢您的帮助!
您可以创建一个空 View
,将 layout_height
和 layout_width
设置为 wrap_content
。
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
然后 link 这个空视图到 BottomSheet
。