带BottomNavigationView的FloatingActionButton(FloatingActionButton with BottomNavigationView)
我无法定位我的FAB。 它应该在右下方,但是在BottonNavigationView之上。
1)我可以实现这个没有RelativeLayout内coordinateLayout?
2)告诉我如何
3)我应该使用FrameLayout作为碎片的容器吗?
<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:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="@dimen/appbar_padding_top" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/AppTheme.PopupOverlay"> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> </FrameLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/fab_electricity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="@dimen/fab_margin" app:layout_anchorGravity="bottom|right|end" app:srcCompat="@drawable/ic_add_electro" /> <android.support.design.widget.BottomNavigationView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="bottom"> </android.support.design.widget.BottomNavigationView> </android.support.design.widget.CoordinatorLayout>
I cant position my FAB. It should be bottom right, but on top of the BottonNavigationView.
1) Can i achieve this without RelativeLayout inside coordinateLayout?
2) Show me how
3) Should i use FrameLayout as a container for fragments?
<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:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="@dimen/appbar_padding_top" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_scrollFlags="scroll|enterAlways" app:popupTheme="@style/AppTheme.PopupOverlay"> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout> <FrameLayout android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> </FrameLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/fab_electricity" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="@dimen/fab_margin" app:layout_anchorGravity="bottom|right|end" app:srcCompat="@drawable/ic_add_electro" /> <android.support.design.widget.BottomNavigationView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="bottom"> </android.support.design.widget.BottomNavigationView> </android.support.design.widget.CoordinatorLayout>
原文:https://stackoverflow.com/questions/43128947
最满意答案
最好不要使用
ifelse
因为'Date'可以强制转换为integer
存储值,而是将(:=
)'Start'指定为'SellDate',然后在'i'中指定逻辑条件以识别' “开始”中的NA'元素或“数字”中的1,并指定(:=
)'BuyDate'中与'i'对应'Start'的元素data[, Start := SellDate][Number==1, Start := BuyDate ][is.na(Start), Start := BuyDate][]
正如@Cath在评论中提到的,这可以分两步完成
data[, Start := SellDate][(Number==1) | is.na(Start), Start := BuyDate][]
It is better not to use
ifelse
as the 'Date' can get coerced tointeger
storage values, instead, we assign (:=
) 'Start' as the 'SellDate', then specify the logical condition in 'i' for identifying the 'NA' elements in 'Start' or the 1 in 'Number' and assign (:=
) the elements in 'BuyDate' that correspond to 'i' to 'Start'data[, Start := SellDate][Number==1, Start := BuyDate ][is.na(Start), Start := BuyDate][]
As @Cath mentioned in the comments, this can be done in two steps
data[, Start := SellDate][(Number==1) | is.na(Start), Start := BuyDate][]
相关问答
更多-
您第一次尝试失败的原因是,只有其中一个事件实际发生时, time[event==2]或time[event==3]评估为numeric(0) 。 DT[id=='A', time[event==2]] ## numeric(0) 解决这个问题的最简单方法是取两次的最大值: time <= max(time[event %in% 2:3]) DT[, state := ifelse(time >= time[event==1] & time <= max(time[event %in% 2:3]), 1, ...
-
最快的方法可能取决于你的数据是什么样子。 这些例子中提到的那些都是可比的: ( twice被@DavidArenburg提及; onceadd被@akrun加入,我不确定如何用replications > 1来对这些进行基准测试,因为对象在基准测试期间实际上被修改了。) DT <- data.table(x=sample(c(NA,"",letters),1e8,replace=TRUE)) DT0 <- copy(DT) DT1 <- copy(DT) DT2 <- copy(DT) DT3 <- co ...
-
你已经走了一个兔子洞。 这是上升的方式: DT[, col5:= shift(col3, fill = -1) == 0 & col3 != 0] # or DT[, col5:= shift(col3, fill = -1) == 0 & col3 != 0, keyby = key(DT)] You've gone down a rabbit hole. Here's the way up: DT[, col5:= shift(col3, fill = -1) == 0 & col3 != 0] ...
-
ifelse with data.table(ifelse with data.table)[2022-09-07]
最好不要使用ifelse因为'Date'可以强制转换为integer存储值,而是将( := )'Start'指定为'SellDate',然后在'i'中指定逻辑条件以识别' “开始”中的NA'元素或“数字”中的1,并指定( := )'BuyDate'中与'i'对应'Start'的元素 data[, Start := SellDate][Number==1, Start := BuyDate ][is.na(Start), Start := BuyDate][] 正如@Cath在评论中提到 ... -
缩短嵌套的ifelse(Shorten nested ifelse)[2023-08-05]
我们可以在data.table使用Map和max.col来完成此操作 TDT[, compare := {d1 <- as.data.table(Map(function(x) x1 < x, .SD)) max.col(d1, "first") *(c(5, 1)[((Reduce(`+`, d1)!=0)+1)])}, .SDcols = x2:x5] #OP's code v1 <- TDT[, ifelse(x1 < x2,1,ifelse(x1 < x3,2,ifelse(x1 < ... -
使用data.table ,我们可以使用:= ,这将更有效(来自@ plafort帖子的示例数据) library(data.table)#v1.9.4+ setDT(df)[X5==0, X6:=1] Usingdata.table, we can use :=, which would be more efficient (example data from @plafort's post) library(data.table)#v1.9.4+ setDT(df)[X5==0, X6:=1]
-
您可以使用联接: # initialize to zero log[, correct := 0L ] # update to 1 if matched log[question_table, on=c(question_id = "id", student_answer = "correct_ans"), correct := 1L ] student question_id student_answer correct 1: b 1 ...
-
这是一种方法,如果列的所有值都是NA ,则给你-Inf (和警告)(如果你愿意,你可以稍后用NA替换它): DT[, lapply(.SD, function(x) max(v[!is.na(x)]))] # x y z v # 1: 6 9 -Inf 9 正如@DavidArenburg所建议的那样,为了确保一切顺利,即使所有值都是NA (没有警告并且直接NA为结果),您可以: DT[, lapply(.SD, function(x) { temp <- v[!is.na(x)] ...
-
好吧,你可以把你喜欢的订单放在某个地方: levelmap = data.table(Level = 1:2, ord = list( c("Conference", "Webinar", "Meeting", "Video"), c("Webinar", "Meeting", "Conference", "Video") )) 然后使用您之前的方法: DT[, r := .I] for (ii in seq(nrow(levelmap))) DT[ Level == level ...
-
ifelse with for循环(ifelse with for loop)[2023-02-06]
根据你的描述,你想检查非列的数量,然后根据这个结果做一些事情(为什么你需要“if”/“ifelse”语句)。 所以,你可以像下面那样实现,并在特定函数中编写内部循环。 yourFunc <- function(x, data) { # do what your want / your loops on "data" # sample, you can check the result in here if(x > 1) 1 else 0 } m = matrix(c(1,2,NA,N ...