我创建了默认的底部导航项目。在其中一个片段中,我添加了ListView
,效果很好。然后我将其更改为RecyclerView
,它被BottomNavigationView
遮盖了。我在做什么错了?
这是主要活动的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
这是片段的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DiaryFragment">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
tools:listitem="@layout/recyclerview_item" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@android:drawable/ic_menu_add"
android:layout_marginBottom="70dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
/>
</android.support.constraint.ConstraintLayout>
当RecyclerView
包含的行超出屏幕显示的容量时,最后一行将部分出现在BottomNavigationView
的后面。如果有任何建议,我将不胜感激。
编辑-这是屏幕截图:
编辑#2:在第一种布局中,如果我将BottomNavigationView
移到LinearLayout
内(感谢@Juanje),并将其android:layout_width
从0dp
更改为{ {1}},然后match_parent
不再掩盖RecyclerView
,但是现在BottomNavigationView
被漂流了:
我正在修补它,如果有任何想法,我将不胜感激。
编辑#3
以下是我在遵循公认的答案以及其他一些调整之后得出的结论。必要的更改是:
1)在第一种布局中:
FloatingActionButton
移到BottomNavigationView
内LinearLayout
中,将BottomNavigationView
从android:layout_width
更改为"0dp"
2)在第二种布局中:
"match_parent"
中,更改FloatingActionButton
从android:layout_marginBottom
到"70dp"
第一个布局文件:
"10dp"
第二个布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:2)
您应将BottomNavigationView
放在LinearLayout
内。
答案 1 :(得分:2)
您需要设置一些约束,否则您的元素会重叠。使用这个:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/navigation"> <!--Added here and one line above; changed height: 0dp height means match constraint-->
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?attr/colorPrimary"
android:elevation="4dp"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
答案 2 :(得分:0)
fragment
元素的重要属性是设置 android:layout_height="0dp"
以匹配约束布局,并添加 app:layout_constraintBottom_toTopOf="@id/nav_view"
以使{ {1}}在fragment
上方。
BottomNavigationView
答案 3 :(得分:0)
这是我对
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
should add all members to my_service.conf as ha.initial_hosts list
cluster member nodes lookup - wait until all join
[4.4e-05] waiting for converge...
[1.003424] waiting for converge...
[2.003765] waiting for converge...
[3.014148] waiting for converge...
[4.027826] waiting for converge...
[5.034108] waiting for converge...
[6.035726] waiting for converge...
[7.039808] waiting for converge...
[8.04352] waiting for converge...
[9.045821] waiting for converge...
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
[10.046889] Converged!...#<Set: {"1.2.3.4", "1.2.3.5"}>
should find the first 2 registered nodes
add 20003 in 3 seconds
[5.4e-05] waiting for recipe to find our new member...
================================================================================
Error executing action `create` on resource 'template[/etc/my_service/my_service.conf]'
================================================================================
Chef::Exceptions::UserIDNotFound
--------------------------------
cannot determine user id for 'dev', does the user exist on this system?
Resource Declaration:
---------------------
# In /var/folders/21/x4vz7kyd19z30q2f_jvn_g3c0000gn/T/chefspec20200202-59873-1g2naeefile_cache_path/cookbooks/my_service/recipes/configure.rb
85: template "#{node[:my_service][:config_file]}" do
86: source "my_service.conf.erb"
87: owner "dev"
88: group "dev"
89: mode "0644"
90: notifies :restart, 'service[my_service]', :delayed
91: variables(
92: {
94: :node_id => node_id,
95: :cluster_members => cluster_nodes,
...
99: }
100: )
102: end
Compiled Resource:
------------------
# Declared in /var/folders/21/x4vz7kyd19z30q2f_jvn_g3c0000gn/T/chefspec20200202-59873-1g2naeefile_cache_path/cookbooks/my_service/recipes/configure.rb:85:in `from_file'
template("/etc/my_service/my_service.conf") do
action [:create]
default_guard_interpreter :default
source "my_service.conf.erb"
declared_type :template
cookbook_name "my_service"
recipe_name "configure"
owner "dev"
group "dev"
mode "0644"
variables {:node_id=>"node1", :cluster_members=>"1.2.3.4,1.2.3.5,1.2.3.6"}
path "/etc/my_service/my_service.conf"
verifications []
end
System Info:
------------
chef_version=15.4.45
platform=ubuntu
platform_version=14.04
ruby=ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]
program_name=/opt/chefdk/embedded/bin/rspec
executable=/Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb
#<Thread:0x00007fbb70636d88@/Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb:138 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
26: from /Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb:139:in `block (4 levels) in <top (required)>'
25: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/server_runner.rb:35:in `converge'
24: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/solo_runner.rb:122:in `converge'
23: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `converge'
22: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `catch'
21: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:704:in `block in converge'
20: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:130:in `converge'
19: from /opt/chefdk/embedded/lib/ruby/2.6.0/forwardable.rb:230:in `execute_each_resource'
18: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:94:in `execute_each_resource'
17: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
16: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
15: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:86:in `step'
14: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:115:in `call_iterator_block'
13: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:96:in `block in execute_each_resource'
12: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:132:in `block in converge'
11: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `run_all_actions'
10: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `each'
9: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `block in run_all_actions'
8: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:74:in `run_action'
7: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/extensions/chef/resource.rb:42:in `run_action'
6: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource.rb:585:in `run_action'
5: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:175:in `run_action'
4: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:197:in `process_resource_requirements'
3: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `run'
2: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `each'
1: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:316:in `block in run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:238:in `run': cannot determine user id for 'my_service', does the user exist on this system? (Chef::Exceptions::UserIDNotFound)
26: from /Users/dan_mordechay/dev/af-chef/cookbooks/my_service/spec/configure_spec.rb:139:in `block (4 levels) in <top (required)>'
25: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/server_runner.rb:35:in `converge'
24: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/solo_runner.rb:122:in `converge'
23: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `converge'
22: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:699:in `catch'
21: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/client.rb:704:in `block in converge'
20: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:130:in `converge'
19: from /opt/chefdk/embedded/lib/ruby/2.6.0/forwardable.rb:230:in `execute_each_resource'
18: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:94:in `execute_each_resource'
17: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
16: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
15: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:86:in `step'
14: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/stepable_iterator.rb:115:in `call_iterator_block'
13: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource_collection/resource_list.rb:96:in `block in execute_each_resource'
12: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:132:in `block in converge'
11: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `run_all_actions'
10: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `each'
9: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:108:in `block in run_all_actions'
8: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/runner.rb:74:in `run_action'
7: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chefspec-7.4.0/lib/chefspec/extensions/chef/resource.rb:42:in `run_action'
6: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/resource.rb:585:in `run_action'
5: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:175:in `run_action'
4: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/provider.rb:197:in `process_resource_requirements'
3: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `run'
2: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:315:in `each'
1: from /opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:316:in `block in run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.4.45/lib/chef/mixin/why_run.rb:238:in `run': template[/etc/my_service/my_service.conf] (my_service::configure line 85) had an error: Chef::Exceptions::UserIDNotFound: cannot determine user id for 'my_service', does the user exist on this system? (Chef::Exceptions::UserIDNotFound)
[1.004191] Found!...#<Set: {"1.2.3.4", "1.2.3.5", "1.2.3.6"}>
should find it once added
的解决方案:
SwipeRefreshLayout
<?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:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/people_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
由BottomNavigationView
包装,看起来像:
ConstraintLayout