安卓开发:如何实现按钮左右滑动
你可以使用 HorizontalScrollView 控件来实现按钮的左右滑动。首先,将三个按钮放在一个 LinearLayout 中,然后将该 LinearLayout 放在一个 HorizontalScrollView 中即可。如下所示:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='客厅'/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='卧室'/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text='厨房'/>
</LinearLayout>
</HorizontalScrollView>
这样,当按钮超出屏幕范围时,用户可以通过水平滚动来查看所有按钮。
原文地址: https://www.cveoy.top/t/topic/owEl 著作权归作者所有。请勿转载和采集!