Gmail Android应用浮动按钮
我想在Android的滚动视图上添加一个浮动按钮。这样,即使我滚动布局,在这种情况下,按钮也应在给定位置(右下)保持恒定。就像Gmail android移动应用一样,它们在右下角具有完整的“发送邮件”按钮,并且背景是可滚动的。
答案 0 :(得分:0)
如果将按钮放在布局的顶部而不是在recyclerview中,则在滚动时它不会移动。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_input_add" />
</androidx.constraintlayout.widget.ConstraintLayout>
答案 1 :(得分:0)
它不是ScrollView
,而是RecyclerView。为此,您可以使用CoordinatorLayout
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</com.google.android.material.appbar.AppBarLayout>
<Your layout with Recycler View/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@android:drawable/ic_menu_edit" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
如果您仍想使用ScrollView,只需将其作为RecyclerView的重力底部同级。
答案 2 :(得分:0)
使约束范围内的“滚动视图”不使主父布局成为滚动视图。
2019-07-09T11:28:23.492083+00:00 app[web.1]: rv = self.dispatch_request()
2019-07-09T11:28:23.492085+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
2019-07-09T11:28:23.492087+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2019-07-09T11:28:23.492090+00:00 app[web.1]: File "/app/potato.py", line 32, in Prediction
2019-07-09T11:28:23.492092+00:00 app[web.1]: b0,b1,b2 = m1.predict(image)
2019-07-09T11:28:23.492094+00:00 app[web.1]: File "/app/label_image.py", line 66, in predict
2019-07-09T11:28:23.492095+00:00 app[web.1]: graph = load_graph(model_file)
2019-07-09T11:28:23.492098+00:00 app[web.1]: File "/app/label_image.py", line 17, in load_graph
2019-07-09T11:28:23.492099+00:00 app[web.1]: graph_def.ParseFromString(f.read())
2019-07-09T11:28:23.492101+00:00 app[web.1]: google.protobuf.message.DecodeError: Error parsing message
2019-07-09T11:28:42.550576+00:00 heroku[router]: at=info method=GET path="/predict" host=potato-image-classifier.herokuapp.com request_id=681def10-d77d-4efb-9806-538a87a3be2e fwd="14.139.34.2" dyno=web.1 connect=1ms service=4ms status=400 bytes=347 protocol=https
2019-07-09T11:29:06.672292+00:00 app[web.1]: <FileStorage: '1 (41).jpg' ('image/jpeg')>
2019-07-09T11:29:07.748293+00:00 app[web.1]: E0709 11:29:07.747753 139833447112832 app.py:1780] Exception on /predict [POST]
2019-07-09T11:29:07.748306+00:00 app[web.1]: Traceback (most recent call last):
2019-07-09T11:29:07.748309+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 2311, in wsgi_app
2019-07-09T11:29:07.748312+00:00 app[web.1]: response = self.full_dispatch_request()
2019-07-09T11:29:07.748319+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1834, in full_dispatch_request
2019-07-09T11:29:07.748321+00:00 app[web.1]: rv = self.handle_user_exception(e)
2019-07-09T11:29:07.748323+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1737, in handle_user_exception
2019-07-09T11:29:07.748325+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2019-07-09T11:29:07.748327+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 36, in reraise
2019-07-09T11:29:07.748330+00:00 app[web.1]: raise value
2019-07-09T11:29:07.748332+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
2019-07-09T11:29:07.748334+00:00 app[web.1]: rv = self.dispatch_request()
2019-07-09T11:29:07.748336+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
2019-07-09T11:29:07.748339+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2019-07-09T11:29:07.748341+00:00 app[web.1]: File "/app/potato.py", line 32, in Prediction
2019-07-09T11:29:07.748343+00:00 app[web.1]: b0,b1,b2 = m1.predict(image)
2019-07-09T11:29:07.748345+00:00 app[web.1]: File "/app/label_image.py", line 66, in predict
2019-07-09T11:29:07.748347+00:00 app[web.1]: graph = load_graph(model_file)
2019-07-09T11:29:07.748350+00:00 app[web.1]: File "/app/label_image.py", line 17, in load_graph
2019-07-09T11:29:07.748352+00:00 app[web.1]: graph_def.ParseFromString(f.read())
2019-07-09T11:29:07.748360+00:00 app[web.1]: google.protobuf.message.DecodeError: Error parsing message
2019-07-09T11:29:07.750486+00:00 heroku[router]: at=info method=POST path="/predict" host=potato-image-classifier.herokuapp.com request_id=dd1018ec-340e-45f3-98de-75f2606289e3 fwd="14.139.34.2" dyno=web.1 connect=1ms service=5630ms status=500 bytes=455 protocol=https