Android 单击scrollview底部的按钮时,在长scrollview上方显示覆盖视图以填充屏幕
我有一个滚动视图,有点长,很容易超出屏幕高度。现在在scrollview的底部,有一个按钮,单击该按钮我执行一些操作。当这些操作完成时,我想显示一个覆盖遮罩,它将填充屏幕 覆盖层Android 单击scrollview底部的按钮时,在长scrollview上方显示覆盖视图以填充屏幕,android,android-layout,Android,Android Layout,我有一个滚动视图,有点长,很容易超出屏幕高度。现在在scrollview的底部,有一个按钮,单击该按钮我执行一些操作。当这些操作完成时,我想显示一个覆盖遮罩,它将填充屏幕 覆盖层 <LinearLayout> <ImageView></ImageView> <TextView>Loading...</TextView> </LinearLayout> 加载。。。 ScrollView布局如下所示 <Scr
<LinearLayout>
<ImageView></ImageView>
<TextView>Loading...</TextView>
</LinearLayout>
加载。。。
ScrollView布局如下所示
<ScrollView>
<LinearLayout>Main content</LinearLayout>
</ScrollView>
主要内容
我希望覆盖遮罩在ScrollView中相对于屏幕而不是父ScrollView的LinearLayout顶部呈现。ScrollView只能有一个子视图。我建议这样做 在布局文件中
<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视图,并在按钮上单击将LinearLayout的可见性设置为
可见
,当您的操作完成时,即当您需要覆盖遮罩消失时,只需将LinearLayout的可见性设置为消失
。android:clickable
属性将确保当显示覆盖遮罩时,它将吞噬所有触摸事件。android:background
属性将应用半透明的黑色覆盖效果。这部分很好,我已经实现了。但这里需要注意的是,第二个线性布局(覆盖遮罩)的高度、宽度设置为匹配父项,将覆盖整个scrollview。现在,如果我在叠加遮罩中设置android:gravity=center,由于叠加遮罩的高度,中心将位于屏幕区域之外的某个地方。我不想将高度、宽度设置为与父项匹配,但只设置可见屏幕区域,以便加载图像位于屏幕中心检查答案中的更新。应该可以解决你的问题。是的,这似乎可行,我不确定这是否是一个好的设计模式。我对android有点陌生,不完全确定什么是好的设计模式。但正如我所说,这似乎是可行的,现在也可以。谢谢,很酷。。别担心,这个设计没有什么问题。这对于添加动画和处理代码具有灵活性,而且不会杂乱无章,并且没有额外的布局或视图被膨胀。因此,随着xml的发展,它没有任何问题。