我有一个 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/