android - 单击 ScrollView 底部的按钮时,在长 ScrollView 上方显示覆盖 View 以填充屏幕

标签 android android-layout

我有一个 ScrollView ,它有点长并且很容易超出屏幕高度。现在,在 ScrollView 的底部有一个按钮,单击该按钮后我会执行一些操作。当这些操作完成后,我想显示一个覆盖屏幕,填充屏幕。

叠加布局

<LinearLayout>
  <ImageView></ImageView>
  <TextView>Loading...</TextView>
</LinearLayout>

ScrollView 布局如下

<ScrollView>
  <LinearLayout>Main content</LinearLayout>
</ScrollView>

我希望覆盖 mask 相对于屏幕呈现在 ScrollView 内 LinearLayout 的顶部,而不是父 ScrollView。

最佳答案

ScrollView 只能有一个 subview 。我建议这样做是这样的

在布局文件中

<FrameLayout 
    android:layout_height="match_parent"
    android:layout_width="match_parent">


    <ScrollView 
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <LinearLayout>Main content</LinearLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/overlay_mask"
        android:clickable="true"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:background="#80000000"
        android:gravity="center"
        android:visibility="gone">
        <ImageView></ImageView>
        <TextView>Loading...</TextView>
   </LinearLayout>

</FrameLayout>

在您的代码中使用 findViewById() 获取 LinearLayout View ,并在按钮 onClick 上将 LinearLayout 的可见性设置为 VISIBLE 以及当您的操作完成时,即当您需要覆盖 mask 消失时只需将 LinearLayout 的可见性设置为 GONE 即可。 android:clickable 属性将确保当显示覆盖 mask 时它将耗尽所有触摸事件。 android:background 属性将应用半透明的黑色叠加效果。

关于android - 单击 ScrollView 底部的按钮时,在长 ScrollView 上方显示覆盖 View 以填充屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30690048/

相关文章:

android - layout_width 和 layout_height 不适用于主题中的 edittext

android - TextView 不显示所有文本

android - Robospice - 我们应该以什么顺序使用 execute()、addListenerIfPending()、getFromCache()

java - 如何更改搜索框的标题?

Android Google Map API 不提供任何类/方法来管理 map 图 block

Android:如何仅为我的应用设置密码/PIN?

android - 平板电脑布局大和土地之间的区别?

android - RelativeLayout 中的 layout_centerInParent 不以模拟器或设备为中心

View 上的 Android float 按钮

android - float 操作按钮和 RecyclerView