gpt4 book ai didi

android - 当 float 按钮到达 NestedScrollView 内 TextView 的相同高度位置时,如何将 float 按钮可见性设置为 GONE?

转载 作者:行者123 更新时间:2023-12-02 16:37:33 25 4
gpt4 key购买 nike

我有以下 XML 文件 -

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_product_page_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/activity_product_page_top_product_layout"
android:layout_width="match_parent"
android:layout_height="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/activity_product_page_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:contentDescription="@string/marketplace_productvendor_page_back_button"
android:onClick="backButtonPressed"
android:src="@drawable/arrow_left"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/activity_product_page_vendor_icon_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:contentDescription="@string/marketplace_productvendor_page_vendor_image"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_width="200dp" />

<FrameLayout
android:id="@+id/activity_product_page_shopping_cart_framelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/activity_checkout_cart_imageView"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:src="@drawable/icons_32_x_32_black_shopping_cart" />

<TextView
android:id="@+id/activity_product_page_shopping_cart_counter"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="end"
android:background="@drawable/textview_round_background"
android:elevation="1dp"
android:gravity="center"
android:maxLines="1"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="10sp"
android:textStyle="bold"
android:visibility="gone"
app:autoSizeMaxTextSize="16sp"
app:autoSizeMinTextSize="10sp"
app:autoSizeStepGranularity="2sp"
app:layout_constraintStart_toEndOf="@+id/activity_checkout_cart_imageView"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SmallSp"
tools:text="1"
tools:visibility="visible" />


</FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/activity_product_page_top_product_layout">

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/activity_product_page_share_product_action_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="end"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
android:alpha="0.5"
android:background="@color/grey_text_cart"
android:backgroundTint="@color/grey_text_cart"
android:elevation="1dp"
android:scaleType="center"
android:src="@drawable/share_product"
app:backgroundTint="@color/white"
app:fabCustomSize="50dp"
app:fabSize="auto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.core.widget.NestedScrollView
android:id="@+id/activity_product_page_nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
android:id="@+id/activity_product_page_nested_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/marketplace_15dp">

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/very_light_grey" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/activity_product_page_brands_breadcrumbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_15dp"
android:fontFamily="@font/noto_sans"
android:text="@string/breadcrumbs_brands"
android:textStyle="bold" />

<TextView
android:id="@+id/activity_product_page_vendor_breadcrumbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_15dp"
android:layout_toEndOf="@id/activity_product_page_brands_breadcrumbs"
android:fontFamily="@font/noto_sans"
android:text="@string/products_breadcrumbs_unknown_vendor"
android:textStyle="bold" />

<TextView
android:id="@+id/activity_product_page_product_breadcrumbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_15dp"
android:layout_toEndOf="@id/activity_product_page_vendor_breadcrumbs"
android:ellipsize="end"
android:fontFamily="@font/noto_sans"
android:maxLines="1"
android:text="@string/activity_product_page_unknown_product"
android:textColor="#979797" />


</RelativeLayout>


<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/marketplace_15dp"
android:background="@color/very_light_grey" />

<androidx.viewpager.widget.ViewPager
android:id="@+id/activity_product_page_view_pager"
android:layout_width="match_parent"
android:layout_height="300dp"
android:paddingStart="40dp"
android:paddingEnd="40dp"
tools:layout_height="300dp" />

<me.relex.circleindicator.CircleIndicator
android:id="@+id/activity_product_page_image_indicator"
android:layout_width="match_parent"
android:layout_height="10dp"
app:ci_drawable="@drawable/currently_selected_product"
app:ci_drawable_unselected="@drawable/currently_unselected_product"
app:ci_height="5dp"
app:ci_width="5dp" />

<LinearLayout
android:id="@+id/activity_product_page_products_details_viewgroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/marketplace_15dp"
android:background="@color/very_light_grey"
android:orientation="vertical">

<TextView
android:id="@+id/activity_product_page_product_title_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:textSize="20sp"
android:textStyle="bold"
tools:text="Products long title" />

<TextView
android:id="@+id/activity_product_page_product_short_description_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
tools:text="Product short description" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp">

<TextView
android:id="@+id/activity_product_page_sold_by"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_sold_by" />

<TextView
android:id="@+id/activity_product_page_vendors_name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/activity_product_page_sold_by"
android:layout_marginStart="5dp"
android:layout_toEndOf="@+id/activity_product_page_sold_by"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_unknown"
android:textStyle="bold"
tools:text="Vendors name, " />

<TextView
android:id="@+id/activity_product_page_fulfilled_by_hard_coded_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activity_product_page_vendors_name_textview"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_fulfilled_by" />

<TextView
android:id="@+id/activity_product_page_fulfilled_by_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/activity_product_page_fulfilled_by_hard_coded_text"
android:layout_marginStart="5dp"
android:layout_toEndOf="@+id/activity_product_page_fulfilled_by_hard_coded_text"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_unknown"
android:textStyle="bold"
tools:text="Project Verte." />

<TextView
android:id="@+id/activity_product_page_sku_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_sku_unknown"
tools:text="SKU: K004" />

</RelativeLayout>

<TextView
android:id="@+id/activity_product_page_product_price_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_fetching_price"
android:textSize="20sp"
android:textStyle="bold"
tools:text="$35.00" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_additional_tax_may_apply_on_checkout" />

<RelativeLayout
android:id="@+id/activity_product_page_availability_view_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_15dp">

<TextView
android:id="@+id/activity_product_page_availability_hardcoded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_availability" />

<TextView
android:id="@+id/activity_product_page_availability_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/activity_product_page_availability_hardcoded"
android:layout_toEndOf="@+id/activity_product_page_availability_hardcoded"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_unknown"
android:textColor="@color/red_delete"
tools:text="In Stock"
tools:textColor="@color/product_available" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/activity_product_page_quantity_picker_viewgroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/marketplace_15dp"
android:visibility="gone"
tools:visibility="visible">

<TextView
android:id="@+id/activity_product_page_quantity_hardcoded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_quantity" />

<NumberPicker
android:id="@+id/activity_product_page_quantity_number_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/activity_product_page_quantity_hardcoded"
android:layout_marginStart="90dp"
android:layout_marginEnd="90dp" />

</RelativeLayout>

<!-- At this point starts the dynamic product attributes (if any exists)
Check ProductPageActivity.java 'setProductPurchaseAttributes()'
for the code -->

<ProgressBar
android:id="@+id/activity_product_page_add_to_cart_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/marketplace_15dp"
android:visibility="gone"
tools:visibility="visible" />

<Button
android:id="@+id/activity_product_page_add_to_cart_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:background="@color/color_black"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_add_to_cart"
android:textColor="@color/white" />

<ProgressBar
android:id="@+id/activity_product_page_buy_now_progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/marketplace_15dp"
android:visibility="gone"
tools:visibility="visible" />

<Button
android:id="@+id/activity_product_page_buy_now_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="@dimen/marketplace_15dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:background="@color/color_black"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_buy_now"
android:textColor="@color/white" />

<TextView
android:id="@+id/activity_product_page_share_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_share" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/marketplace_14dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="@dimen/marketplace_14dp"
android:fontFamily="@font/noto_sans"
android:text="@string/activity_product_page_related_products"
android:textSize="22sp"
android:textStyle="bold" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/activity_product_page_related_recycleview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="@dimen/marketplace_15dp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:listitem="@layout/fragment_marketplace_products_row_item" />

<View
android:id="@+id/activity_product_page_bottom_view"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="@dimen/marketplace_15dp"
android:layout_marginBottom="60dp"
android:background="@color/light_black"
android:visibility="gone"
tools:visibility="visible" />


</LinearLayout>


</LinearLayout>

</androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

看起来像这样 -

enter image description here

我正在尝试实现一种逻辑,该逻辑将使 float 栏在到达名为 - activity_product_page_share_textview 的 TextView 时消失。 。我尝试实现 new NestedScrollView.OnScrollChangeListener()在我的 NestedScrollView 上,但我从scrollX和scrollY获得的值完全不相关 - 似乎它根据当前可用的屏幕空间计算值,并且(也许)还根据我的滚动速度 - 绝对不是根据 NestedScrollView ViewGroup。

另外,我希望 float 栏在 TextView 的 Y 位置下方时返回。两者都通过一些简单的淡入/淡出动画出现和消失。

我该如何实现它?

最佳答案

也许是这样的?需要一些优化(例如 float 按钮不需要位于每个滚动条上),但这与想法有关。

activity_product_page_nested_scroll_view.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { _, _, _, _, _ ->
val locationOfTextView = IntArray(2)
val locationOfFloatingButton = IntArray(2)
activity_product_page_share_textview.getLocationInSurface(locationOfTextView)
activity_product_page_share_product_action_button.getLocationInSurface(
locationOfFloatingButton
)

if (locationOfTextView[1] >= locationOfFloatingButton[1] &&
locationOfTextView[1] + activity_product_page_share_textview.height <= locationOfFloatingButton[1] + activity_product_page_share_product_action_button.height
) {
if (activity_product_page_share_textview.alpha == 1F)
activity_product_page_share_textview.animate().alpha(0F).setDuration(200L).start()
} else {
if (activity_product_page_share_textview.alpha < 1F)
activity_product_page_share_textview.animate().alpha(1F).setDuration(200L).start()
}
})

关于android - 当 float 按钮到达 NestedScrollView 内 TextView 的相同高度位置时,如何将 float 按钮可见性设置为 GONE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60360327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com