我正在尝试在我的一个活动中实现Bottom表,我对它的行为方式感到困惑!
所以这就是问题,我有一个活动,我试图显示底部表格,我看到:
如果我们不设置app:behavior_peekHeight属性,那么Bottom表永远不会工作
如果你将PeekHeight设置为小于30dp的东西(基本上只是为了将其隐藏在屏幕上)
app:behavior_peekHeight在布局文件超过30DP并尝试设置的状态bottomSheetBehavior来STATE_HIDDEN与这个错误在你onCreate方法您的应用程序崩溃引起的:
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference at android.support.design.widget.BottomSheetBehavior.setState(BottomSheetBehavior.jav a:440)
at myapp.activity.SomeActivity.onCreate(SomeActivity.java:75)
Run Code Online (Sandbox Code Playgroud)
我真的很困惑,为什么它不允许我隐藏在onCreate中?或者为什么我们不能将peekHeight设置为0以便它在屏幕上不可见,除非我们调用STATE_EXPANDED甚至不设置该属性应该默认隐藏它!或者至少我应该可以将它设置为隐藏在我的onCreate中!
我错过了什么吗?或BottomSheet的行为僵硬?
我的BottomSheet的布局文件是这样的:
<LinearLayout 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:background="@android:color/white"
android:layout_height="100dp"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="40dp" <!-- I cant set this less than 30dp just to hide-->
app:layout_behavior="@string/bottom_sheet_behavior"
tools:context="someActivity"
android:id="@+id/addressbottomSheet"
tools:showIn="@layout/some_activity">
Run Code Online (Sandbox Code Playgroud)
在我的活动中,我正在做这样的事情:
@InjectView(R.id.addressbottomSheet)
View bottomSheetView;
@Override
protected void onCreate(Bundle savedInstanceState) {
....
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetView);
// only if I …Run Code Online (Sandbox Code Playgroud) 我有一个哈希数组,我需要根据两个不同的键值对进行排序.
这是我要排序的数组:
array_group = [
{operator: OR, name: "some string", status: false},
{operator: AND, name: "other string", status: false},
{operator: _NOT_PRESENT, name: "another string", status: true},
{operator: AND, name: "just string", status: true}
]
Run Code Online (Sandbox Code Playgroud)
我想排序array_group所以我有status: true第一个项目,然后是status: false,然后是项目,operator: _NOT_PRESENT最后根据名称对其进行排序,结果如下:
array_group = [
{operator: AND, name: "just string", status: true},
{operator: AND, name: "other string", status: false},
{operator: OR, name: "some string", status: false},
{operator: _NOT_PRESENT, name: "another string", status: true},
]
Run Code Online (Sandbox Code Playgroud)
有没有办法可以在不创建子数组并对其进行排序并将它们连接起来的情况下完成此操作?
我有一个对象数组,可能包含具有相同属性值的对象.我试图根据多个属性(不只是一个属性值)删除重复项
class Font
attr_accessor :color, :name, :type
end
a = <@color="blue", @name="s", @type="bold">
b = <@color="blue", @name="r", @type="italic">
c = <@color="green", @name="t", @type="bold">
d = <@color="blue", @name="s", @type="some_other_type">
fonts = [a, b, c, d]
Run Code Online (Sandbox Code Playgroud)
我需要根据颜色,名称的值来消除重复(我不关心类型)
我试过的
uniq_fonts = fonts.uniq { |f| f.name.to_s + f.color.to_s}
Run Code Online (Sandbox Code Playgroud)
有没有更清洁的方法可以达到相同的效果?
注意:这些是对象而不是哈希.我知道我们可以使用:
fonts.uniq { |f| f.values_at(:name, :color)}
Run Code Online (Sandbox Code Playgroud)
如果他们是哈希