第三方FloatingActionButton图书馆CoordinatorLayout [英] Third Party FloatingActionButton Library in CoordinatorLayout
问题描述
当我使用从谷歌支持库FAB的 CoordinatorLayout
按预期工作,虽然FutureSimple库是没有的。 (这是正在由小吃吧隐藏
)。
我怎样才能使与第三方库的工作 CoordinatorLayout
fragment_comic.xml
< RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的TextView
机器人:ID =@ + ID /标题
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=CENTER_HORIZONTAL
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:文字=@字符串/ default_title
机器人:textAppearance =?机器人:textAppearanceLarge
机器人:layout_centerHorizontal =真/><的TextView
机器人:ID =@ + ID / ALT
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID /标题
机器人:layout_centerHorizontal =真
机器人:layout_gravity =CENTER_HORIZONTAL
机器人:fadeScrollbars =假
机器人:比重=中心
机器人:MAXLINES =4
机器人:文字颜色=@彩色/黑白
机器人:paddingBottom会=13dp
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:滚动条=垂直
机器人:文字=@字符串/ default_alt
机器人:textAppearance =:/>中的Android textAppearanceMedium?< ImageView的
机器人:ID =@ + ID / ImageView的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ + ID / ALT
机器人:adjustViewBounds =假
机器人:layout_marginBottom =10dp
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:scaleType =fitCenter/>
< / RelativeLayout的>< com.getbase.floatingactionbutton.FloatingActionsMenu
机器人:ID =@ + ID / famMain
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_addButtonColorNormal =@彩色/ material_orange
晶圆厂:fab_addButtonSize =正常
FAB:fab_addButtonStrokeVisible =真
FAB:fab_expandDirection =涨
机器人:layout_gravity =底部|结束>< com.getbase.floatingactionbutton.FloatingActionButton
机器人:ID =@ + ID / fab_random
机器人:SRC =@绘制/ ic_random
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_colorNormal =@彩色/ material_orange
FAB:fab_size =迷你/>< com.getbase.floatingactionbutton.FloatingActionButton
机器人:ID =@ + ID / fab_download
机器人:SRC =@绘制/ ic_download
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_colorNormal =@彩色/ material_orange
FAB:fab_size =迷你/>< com.getbase.floatingactionbutton.FloatingActionButton
机器人:ID =@ + ID / fab_browser
机器人:SRC =@绘制/ ic_open_browser
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_colorNormal =@彩色/ material_orange
FAB:fab_size =迷你/>< /com.getbase.floatingactionbutton.FloatingActionsMenu>
然后在我的Java类,我开始我的FloatingActionsMenu以
FloatingActionsMenu famView =(FloatingActionsMenu)getActivity()findViewById(R.id.famMain)。
然后我将其与
设置为我的小吃吧 Snackbar.make(famView,悬停文本复制到剪贴板,Snackbar.LENGTH_SHORT).show();
在小吃吧是覆盖在FloatingActionMenu的原因是因为你设置,作为小吃吧的观点:
Snackbar.make(famView,悬停文本复制到剪贴板,Snackbar.LENGTH_SHORT).show();
你真正需要做的,是在将用于显示小吃吧布局的底部添加 CoordinatorLayout
。这样看来下面一切你可以在一个时尚的LinearLayout设置此。这是你的XML编辑版:
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直> < android.support.design.widget.CoordinatorLayout
的xmlns:FAB =http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / coordinatorLayout
机器人:layout_height =0dp
机器人:layout_width =match_parent
机器人:layout_weight =1> < RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的TextView
机器人:ID =@ + ID /标题
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=CENTER_HORIZONTAL
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:文字=测试
机器人:textAppearance =?机器人:textAppearanceLarge
机器人:layout_centerHorizontal =真/> <的TextView
机器人:ID =@ + ID / ALT
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID /标题
机器人:layout_centerHorizontal =真
机器人:layout_gravity =CENTER_HORIZONTAL
机器人:fadeScrollbars =假
机器人:比重=中心
机器人:MAXLINES =4
机器人:文字颜色=@机器人:彩色/黑白
机器人:paddingBottom会=13dp
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:滚动条=垂直
机器人:文字=测试Alt键
机器人:textAppearance =:/>中的Android textAppearanceMedium? < ImageView的
机器人:ID =@ + ID / ImageView的
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ + ID / ALT
机器人:adjustViewBounds =假
机器人:layout_marginBottom =10dp
机器人:paddingLeft =@扪/ activity_horizontal_margin
机器人:paddingRight =@扪/ activity_horizontal_margin
机器人:scaleType =fitCenter/>
< / RelativeLayout的> < com.getbase.floatingactionbutton.FloatingActionsMenu
机器人:ID =@ + ID / famMain
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_addButtonColorNormal =@机器人:彩色/黑白
晶圆厂:fab_addButtonSize =正常
FAB:fab_addButtonStrokeVisible =真
FAB:fab_expandDirection =涨
机器人:layout_gravity =底部|结束> < com.getbase.floatingactionbutton.FloatingActionButton
机器人:ID =@ + ID / fab_random
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_colorNormal =@机器人:彩色/黑白
FAB:fab_size =迷你/> < com.getbase.floatingactionbutton.FloatingActionButton
机器人:ID =@ + ID / fab_download
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_colorNormal =@机器人:彩色/黑白
FAB:fab_size =迷你/> < com.getbase.floatingactionbutton.FloatingActionButton
机器人:ID =@ + ID / fab_browser
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
FAB:fab_colorNormal =@机器人:彩色/黑白
FAB:fab_size =迷你/> < /com.getbase.floatingactionbutton.FloatingActionsMenu> < android.support.design.widget.FloatingActionButton
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / testFAB
机器人:layout_gravity =底部|开始/> < /android.support.design.widget.CoordinatorLayout> < android.support.design.widget.CoordinatorLayout
机器人:ID =@ + ID /小吃店
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
然后,您可以得到这样的小吃店观点:
CoordinatorLayout小吃店=(CoordinatorLayout)findViewById(R.id.snackbar);
和使它像这样的:
Snackbar.make(小吃店,悬停文本复制到剪贴板,Snackbar.LENGTH_SHORT).show();
I am trying to use futuresimple's FloatingActionButton
library to use a FloatingActionMenu
inside a CoordinatorLayout
so when I display a Snackbar
the FAB will move up and not be hidden by the Snackbar
. The FloatingActionMenu
is working perfectly although I have noticed the third-party library is not working inside the CoordinatorLayout
.
When I use the support library FAB from Google the CoordinatorLayout
is working as expected, although the library by FutureSimple is not. (It is being hidden by the Snackbar
).
How can I make the third party library work with the CoordinatorLayout
?
fragment_comic.xml
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:text="@string/default_title"
android:textAppearance="?android:textAppearanceLarge"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/alt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:fadeScrollbars="false"
android:gravity="center"
android:maxLines="4"
android:textColor="@color/black"
android:paddingBottom="13dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:scrollbars="vertical"
android:text="@string/default_alt"
android:textAppearance="?android:textAppearanceMedium" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/alt"
android:adjustViewBounds="false"
android:layout_marginBottom="10dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:scaleType="fitCenter" />
</RelativeLayout>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/famMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_addButtonColorNormal="@color/material_orange"
fab:fab_addButtonSize="normal"
fab:fab_addButtonStrokeVisible="true"
fab:fab_expandDirection="up"
android:layout_gravity="bottom|end">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_random"
android:src="@drawable/ic_random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/material_orange"
fab:fab_size="mini"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_download"
android:src="@drawable/ic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/material_orange"
fab:fab_size="mini"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_browser"
android:src="@drawable/ic_open_browser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/material_orange"
fab:fab_size="mini"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
then in my Java class I initiate my FloatingActionsMenu with
FloatingActionsMenu famView = (FloatingActionsMenu) getActivity().findViewById(R.id.famMain);
then I set it to my Snackbar with
Snackbar.make(famView, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show();
The reason the Snackbar is overlaying the FloatingActionMenu is because you are setting that as the view for the Snackbar:
Snackbar.make(famView, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show();
What you really need to do here is add a CoordinatorLayout
at the bottom of your layout that will be used to display the Snackbar. You can set this in a LinearLayout fashion so that it appears below everything else. Here is an edited version of your XML:
<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.design.widget.CoordinatorLayout
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:text="Test"
android:textAppearance="?android:textAppearanceLarge"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/alt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:fadeScrollbars="false"
android:gravity="center"
android:maxLines="4"
android:textColor="@android:color/black"
android:paddingBottom="13dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:scrollbars="vertical"
android:text="Test Alt"
android:textAppearance="?android:textAppearanceMedium" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/alt"
android:adjustViewBounds="false"
android:layout_marginBottom="10dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:scaleType="fitCenter" />
</RelativeLayout>
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/famMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_addButtonColorNormal="@android:color/black"
fab:fab_addButtonSize="normal"
fab:fab_addButtonStrokeVisible="true"
fab:fab_expandDirection="up"
android:layout_gravity="bottom|end">
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@android:color/black"
fab:fab_size="mini"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@android:color/black"
fab:fab_size="mini"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_browser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@android:color/black"
fab:fab_size="mini"/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/testFAB"
android:layout_gravity="bottom|start"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/snackbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Then, you can get the snackbar view like this:
CoordinatorLayout snackbar = (CoordinatorLayout) findViewById(R.id.snackbar);
And make it like this:
Snackbar.make(snackbar, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show();
这篇关于第三方FloatingActionButton图书馆CoordinatorLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!