【问题标题】:I need to use scrollview correctly我需要正确使用滚动视图
【发布时间】:2014-11-05 23:01:23
【问题描述】:

我有 3 个按钮,滚动视图包含文本和图像。 我只想要图像和文本的滚动视图效果,并且我的 3 个按钮固定在滚动视图上,我该怎么做?

【问题讨论】:

    标签: android android-layout android-scrollview xml-layout


    【解决方案1】:

    使用FrameLayout

    下面展示了带有图像的ScrollView 上方带有三个按钮的顶栏示例。

    FrameLayout 会按照声明的顺序渲染他们的孩子。对于下面的示例,首先渲染ScrollView,最后渲染LinearLayout 按钮栏。这会将栏放置在滚动视图上方并提供所需的效果。

    ScrollView 之所以有LinearLayout 作为孩子,是因为他们只能有一个孩子。

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
    
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
    
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
            </LinearLayout>
        </ScrollView>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="horizontal">
    
            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"/>
    
            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"/>
    
            <Button
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"/>
        </LinearLayout>
    </FrameLayout>
    

    【讨论】:

    • 非常感谢,另一个问题 :) 如何将按钮设置到屏幕底部?
    • 在按钮栏布局上使用 android:layout_gravity="bottom"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 2021-02-25
    • 1970-01-01
    相关资源
    最近更新 更多