如何使按钮随水平滚动条移动?
我的背景中有一张地图图片,底部有一个按钮,我想用水平滚动条进行滚动。它在开始时与屏幕右侧对齐,我想将其保留在那里。这可能吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/mapBackground">
<HorizontalScrollView android:id="@+id/horizontalScrollView1"
android:layout_height="fill_parent"
android:scrollbars="none" android:layout_width="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1"
android:background="@drawable/large_map" android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom">
<LinearLayout android:id="@+id/linearLayout4" android:layout_width="fill_parent"
android:layout_height="400dp">
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout5"
android:layout_width="320dp" android:gravity="right">
<Button android:background="@drawable/bt_play_circle"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/playButton"></Button>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
I have a picture of a map in the background with a button on the bottom and I want to make this scroll with the horizontal scroll bar. It is aligned to the right of the screen at the start and I would like to keep it there. Is this possible?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/mapBackground">
<HorizontalScrollView android:id="@+id/horizontalScrollView1"
android:layout_height="fill_parent"
android:scrollbars="none" android:layout_width="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1"
android:background="@drawable/large_map" android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom">
<LinearLayout android:id="@+id/linearLayout4" android:layout_width="fill_parent"
android:layout_height="400dp">
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout5"
android:layout_width="320dp" android:gravity="right">
<Button android:background="@drawable/bt_play_circle"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/playButton"></Button>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您希望在滚动时按钮保留在地图的右侧吗?
将按钮放置在 HorizontalScrollView 之外。
例如,您可以使用RelativeLayout而不是顶部的LinearLayout。
You want the button to stay on the right side over the map while you are scrolling?
Place the button outside the HorizontalScrollView.
You could for example use RelativeLayout instead of the top LinearLayout.