首页 > 解决方案 > 如何在 ScrollView 中的 ImageButton 上制作静态 TextView?

问题描述

        <ImageButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/busfoto2" />

    </LinearLayout>
</ScrollView>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Bus Locations"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"/>

我试过了,但滚动屏幕时文本仍在移动,我想在特定的 ImageButton 上修复它

标签: androidxmltextviewscrollviewimagebutton

解决方案


将 Button 和 TextView 放入 FrameLayout 中,如下所示:

    <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<ImageButton
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/busfoto2"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Bus Locations"/></FrameLayout>

推荐阅读