首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在android中将Scrollview隐藏在Imageview后面,反之亦然

在Android中,将ScrollView隐藏在ImageView后面,或者将ImageView隐藏在ScrollView后面,可以通过使用FrameLayout或ConstraintLayout来实现。

  1. 使用FrameLayout: FrameLayout是一种简单的布局容器,它允许子视图重叠在一起。你可以将ScrollView和ImageView作为FrameLayout的子视图,并使用android:layout_gravity属性来控制它们的位置。
代码语言:xml
复制
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <!-- ScrollView的内容 -->

    </ScrollView>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/image"
        android:scaleType="centerCrop" />

</FrameLayout>

在上面的示例中,ScrollView的android:visibility属性设置为gone,使其在初始状态下不可见。ImageView则会显示在最上层。

  1. 使用ConstraintLayout: ConstraintLayout是一种灵活的布局容器,可以通过约束关系来控制子视图的位置。你可以使用app:layout_constraintTop_toTopOfapp:layout_constraintBottom_toBottomOf属性将ScrollView和ImageView垂直对齐,并使用app:layout_constraintStart_toStartOfapp:layout_constraintEnd_toEndOf属性将它们水平对齐。
代码语言:xml
复制
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <!-- ScrollView的内容 -->

    </ScrollView>

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/image"
        android:scaleType="centerCrop"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

在上面的示例中,ScrollView的android:visibility属性设置为gone,使其在初始状态下不可见。ImageView则会显示在最上层。

这样,你就可以根据需要在ScrollView和ImageView之间切换显示和隐藏。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

屏幕宽高不够,滚动视图ScrollView来凑

一、ScrollView概述 从前面的学习有的同学可能已经发现,当拥有很多内容时屏幕显示不完,显示不全的部分完全看不见。但是实际项目里面,很多内容都不止一个屏幕宽度或高度,那怎么办呢?...默认情况下,ScrollView只是为其他组件添加垂直滚动条,如果应用需要添加水平滚动条,则可借助于另一个滚动视图HorizontalScrollView来实现。...android:scrollbarStyle:设置滚动条的风格和位置。属性值有以下几个: outsideInset:该ScrollBar显示视图(view)的边缘,增加了view的padding....继续使用WidgetSample工程的advancedviewsample模块,app/main/res/layout/目录下创建scrollview_layout.xml文件,在其中填充如下代码片段...="vertical"> <ImageView android:id="@+id/imageView" android:layout_width

3K60

Material Design 实战 之 第六弹 —— 可折叠式标题栏(CollapsingToolbarLayout) & 系统差异型的功能实现(充分利用系统状态栏空间)

就表示该控件会出现在系统状态栏里; 2.2 程序的主题中将状态栏颜色指定成透明色; 主题中将android:statusBarColor属性的值指定成@android:color...不管是ScrollView还是NestedScroIIView,它们的内部都只允许存在一个直接子布局。...我水果详情界面的逻辑中,findViewbyid写错成了卡片水果列表界面的ImageView的id: ?...方法很简单,主题中将android:statusBarColor属性的值指定成@android:color/transparent即可。...然后FruitAcuvityTheme中将状态栏的颜色指定成透明色, 由于values-v21目录是只有Android5.0及以上的系统才会去读取的, 因此这么声明是没有问题的。

2.2K40
领券