在相对布局内创建与滚动视图大小相同的视图

时间:2016-03-18 15:35:14

标签: android xml

我正在尝试对我的相对布局进行半透明视图,它可以正常工作,直到我旋转屏幕或在TextInputLayout中显示错误消息。当布局需要滚动视图以查看所有元素时,会发生此问题。 下面是我用来使这个背景覆盖我的相对布局的代码

<ScrollView
    android:scrollbars="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:layout_weight="1"
    android:isScrollContainer="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/backgroundImage">

<View
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:alpha="0.79"/> 
</RelativeLayout>
</ScrollView>

我的问题是如何让自定义视图始终与滚动视图的大小相同。

2 个答案:

答案 0 :(得分:1)

使用线性布局而不是相对布局,并设置布局权重1,它将适用于每个角度

答案 1 :(得分:0)

尝试将RelativeLayout属性更改为这些

android:layout_width="match_parent"
android:layout_height="match_parent"

它应该做的工作。

相关问题