Jus*_*ain 9 android floating-action-button
我无法让浮动操作按钮(FAB)出现在正确的位置.我希望它出现在标题和导航抽屉中的第一个项目之间.
目前,我已经将它显示在标题的右下角而不是第1和第2个元素之间的行顶部(第一个元素=标题和第二个元素= recyclerview中的第一个项目).
我的应用正在使用以下appcompat项:
我正在使用导航抽屉,但我无法使用NavigationView,因为我需要自定义项目条目而不加载简单的菜单.
如您所知,抽屉实际上不是两种不同的控件.标题实际上是RecyclerView中的'0'元素.我不知道这是否有所作为.
这是我在RecyclerView中的标题/"0视图"的当前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"
android:layout_width="match_parent"
android:layout_height="@dimen/navdrawer_image_height">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navDrawerHeaderView"
android:layout_width="match_parent"
android:layout_height="@dimen/navdrawer_image_height">
<ImageView
android:id="@+id/navdrawer_image"
android:layout_width="wrap_content"
android:layout_height="@dimen/navdrawer_image_height"
android:contentDescription="@string/cd_navdrawer_image"
android:scaleType="centerCrop"
android:src="@drawable/bg_material_design" />
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_image"
android:layout_width="@dimen/navdrawer_user_picture_size"
android:layout_height="@dimen/navdrawer_user_picture_size"
android:src="@drawable/ic_launcher"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
app:border_width="2dp"
app:border_color="#FF000000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appNameTextView"
android:text="App Name"
android:textStyle="bold"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentBottom="true"
android:textColor="@android:color/white"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/button_account"
app:layout_anchor="@id/navDrawerHeaderView"
app:layout_anchorGravity="bottom|right|end"
app:elevation="4dp"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我想我可能在错误的位置/文件中有FAB.这是抽屉的xml.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<!-- Content layout -->
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar"/>
<FrameLayout
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/init_background">
</FrameLayout>
</LinearLayout>
<!-- Pages -->
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ffffff"
android:scrollbars="vertical"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
救命!!!!!
示例抽屉片段布局包含您现有的RecyclerView:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="200dp">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00"
android:id="@+id/header"/>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:scrollbars="vertical"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:layout_margin="5dp"
android:clickable="true"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2491 次 |
| 最近记录: |