问题描述
编辑:查看Using在ViewPager片段(下载链接)全code中的主/从模板
我有一个工具栏和 recyclerView
。当布局第一次充气 recyclerView的最后一个项目
超出屏幕的涡旋能区域的,因此是不可见的。转动后出现的项目。很明显,在工具栏按下 recyclerView
屏幕边界之外。如果我添加填充到 recyclerView
的底部工具栏的高度问题解决了但只适用于布局的初步通货膨胀。旋转后我留下在屏幕的底部的间隙。我使用SDK的23。
一个可能的解决方法将是布局的第一个充气后以编程方式移除填充。我想我可以使用:
onCreateView(){如果(=的onSaveInstanceState空!)removePadding();}
不过,我宁愿没有做一个狡猾的变通。
我的应用程序基本上是完全一样的Android Studio中提供的主/详细信息流模板,但我用碎片和一个单一的活动。有在模板中没有这样的问题。
任何想法?
fragment_item_list.xml
<?XML版本=1.0编码=UTF-8&GT?;
< android.support.design.widget.CoordinatorLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真正的> < android.support.design.widget.AppBarLayout
机器人:ID =@ + ID / app_bar
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:主题=@风格/ AppTheme.AppBarOverlay> < android.support.v7.widget.Toolbar
机器人:ID =@ + ID /工具栏
机器人:layout_width =match_parent
机器人:layout_height =?ATTR / actionBarSize
应用:popupTheme =@风格/ AppTheme.PopupOverlay/> < /android.support.design.widget.AppBarLayout> <的FrameLayout
机器人:ID =@ + ID /的FrameLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior> <包括布局=@布局/ item_list/>
< /&的FrameLayout GT; < android.support.design.widget.FloatingActionButton
机器人:ID =@ + ID / FAB
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =底部|结束
机器人:layout_margin =@扪/ fab_margin
机器人:SRC =@机器人:可绘制/ ic_dialog_email/>
< /android.support.design.widget.CoordinatorLayout>
item_list.xml
<?XML版本=1.0编码=UTF-8&GT?;
< android.support.v7.widget.RecyclerView的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / item_list
机器人:名字=com.idragonit.scrolltabs.ItemListFragment
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_marginLeft =16DP
机器人:layout_marginRight =16DP
应用:的layoutManager =LinearLayoutManager
工具:上下文=com.idragonit.scrolltabs.ItemListActivity
工具:列表项=@布局/ item_list_content/>
item_list_content.xml
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向> <的TextView
机器人:ID =@ + D / I
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =@扪/ text_margin
机器人:ATTR / textAppearanceListItemtextAppearance = /> <的TextView
机器人:ID =@ + ID /内容
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =@扪/ text_margin
机器人:ATTR / textAppearanceListItemtextAppearance = />
< / LinearLayout中>
ItemListFragment.java的段
工具栏=(栏)root.findViewById(R.id.toolbar);
toolbar.setTitle(列表);
我说:
的android:layout_gravity =fill_vertical
机器人:ATTR / actionBarSizelayout_marginBottom =
要item_list.xml。该问题仍然存在。第一次的布局被充气它表明如预期的底部元件。旋转到横向和回纵向后留下一个余量的动作条的尺寸在屏幕的底部。
此问题不会在Android Studio中可用的主/详细信息流模板和code代表item_list.xml发生,item_list_twopane.xml和activity_item_list是完全一样item_list使用code。 XML,土地/ item_list.xml和fragment_item_list.xml在我的项目。然而,正如所附图片显示,该AppBar的preVIEW展示了Android模板中的弹性空间,但不是我的code。
编辑:当我点击它导航到Android SDK中的values.xml不同的线路,这与启动模板?ATTR / actionBarSize参考<申报-设置样式名称= AppCompatTheme>
。 code在我的应用程序在同一行引用开始用不同的线<申报-设置样式名称=主题方式>
截图:
结果
EDIT: See Using the Master/Detail template in ViewPager Fragments (download link) for full code
I have a toolbar and a recyclerView
. When the layout is first inflated the last item of the recyclerView
is out of the scroll-able region of the screen and is therefore not visible. After rotating the item appears. It is apparent that the toolbar is pushing the recyclerView
outside the boundaries of the screen. If I add padding to the bottom of the recyclerView
with the height of the toolbar the issue is resolved BUT only for the initial inflation of the layout. After rotation I am left with a gap on the bottom of the screen. I'm using sdk 23.
A possible workaround would be to programmatically remove the padding after the very first inflation of the layout. I assume I could use:
onCreateView(){ if (onSaveInstanceState != null) removePadding();}
However, I'd rather not have to do a dodgy work-around.
My app is basically exactly the same as the Master/Detail-flow template supplied in Android Studio, except that I use fragments and a single Activity. There is no such issue in the template.
Any ideas?
fragment_item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/item_list" />
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView 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/item_list"
android:name="com.idragonit.scrolltabs.ItemListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context="com.idragonit.scrolltabs.ItemListActivity"
tools:listitem="@layout/item_list_content" />
item_list_content.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:textAppearance="?attr/textAppearanceListItem" />
</LinearLayout>
snippet of ItemListFragment.java
Toolbar toolbar = (Toolbar) root.findViewById(R.id.toolbar);
toolbar.setTitle("List");
I added:
android:layout_gravity="fill_vertical"
android:layout_marginBottom="?attr/actionBarSize"
to item_list.xml. The issue persists. The first time the layout is inflated it shows the bottom element as expected. After rotating to landscape and back to portrait it leaves a margin the size of the actionBar at the bottom of the screen.
This issue does not happen in the Master/Detail-flow template available in Android Studio and the code for item_list.xml, item_list_twopane.xml and activity_item_list are exactly the same as the code used in item_list.xml, land/item_list.xml and fragment_item_list.xml in my project. Yet, as the attached images show, the preview of the AppBar shows the flexible space in the Android template but not my code.
EDIT: When I click on the reference for "?attr/actionBarSize" in the template it navigates to a different line in android SDK's values.xml, which starts with <declare-styleable name="AppCompatTheme">
. The same line of code in my app references a different line starting with<declare-styleable name="Theme">
.
Screenshots:
这篇关于RecyclerView和工具栏,不能滚动底部项目进入视野的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!