小编Eug*_*sov的帖子

ConstraintLayout beta5 wrap_content没有正确包装

我在RecyclerView中有一个ViewHolder的XML布局.

此布局的根是ConstraintLayout,其高度设置为wrap_content.

在这个平面层次结构中,有3个文本视图和一个具有固定高度的图像视图; 考虑到:

<ConstraintLayout>
     <TextView height=wrap>
     <TextView height=wrap>
     <TextView height=wrap>
     <ImageView height=150dp>
</ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这是一个相对简单的布局.在beta4这是它的外观在设计(并最终在运行时,每个recyclerView细胞):

BETA4

为"繁文缛节"道歉,但它是NDA等等.

话虽这么说,要素是:

3个文本视图(红色录制带有漂亮的紫色背景)高度为150dp的ImageView是灰色的.

紫色背景应用于根ConstraintLayout.一切都好.

现在这就是它的外观,不需要对Beta 5进行任何修改:

beta5的

正如您所看到的,紫色(根)约束布局现在"混淆",并且不会像过去那样包装内容.

我试过的事情:

  1. 添加app:layout_constraintHeight_default="wrap"到ConstraintLayout(并传播).没有什么区别.

  2. ImageView有一个app:layout_constraintBottom_toBottomOf="parent"我试图删除的约束,也没有任何区别.

  3. 恢复到beta4 :)

为了记录,这是完整的布局(由于相同的原因,id已被重命名为出于繁文缛节的原因而没有工具:文本或类似的).布局在其他方面完全相同.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="wrap_content"
    android:background="@color/colorAccent">

    <TextView
        android:id="@+id/toplabel"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@+id/top_bottom_label"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/top_right_label"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/top_right_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="8dp"
        android:ellipsize="end"
        android:gravity="end"
        android:maxLines="1"
        android:text=""
        app:layout_constraintBottom_toTopOf="@+id/top_bottom_label"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintLeft_toRightOf="@+id/toplabel"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed" />

    <TextView
        android:id="@+id/top_bottom_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-constraintlayout constraint-layout-chains

4
推荐指数
1
解决办法
2197
查看次数

ConstraintLayout - 下面的RecyclerView按钮不遵守约束

我在ConstraintLayout中有一个RecyclerView和一个按钮.我希望Button位于顶部,而RecyclerView位于其下方.尝试设置app:layout_constraintTop_toBottomOf="@+id/button"为RecyclerView,但它不尊重.它看起来像这样:

结果视图

我想在Button下方使用RecyclerView.这是我的代码:

<android.support.constraint.ConstraintLayout
    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="match_parent">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:layout_marginTop="16dp"
        android:text="Button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button" />

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

parent为Button 设置了开始,顶部,结束和底部约束.对于RecyclerView,开始和结束parent以及顶部约束到底部button

我究竟做错了什么?

android android-constraintlayout

4
推荐指数
2
解决办法
3591
查看次数

swift 3 获取最近的小时数列表

好的,我let date = Date()在 Swift 3 中,我需要获取最近的钟点列表。

假设当前日期是2017-02-08 15:24:56 +0000这样所需的列表

2017-02-08 15:30:00 +0000
2017-02-08 15:45:00 +0000
2017-02-08 16:00:00 +0000

我怎样才能得到那个日期列表?

编辑 1 2/8/2017 下午 5:54

这是我刚刚尝试做的事情,看起来它得到了我需要的结果。

    let currentDate = Date()
    var minute = Calendar.current.component(.minute, from: currentDate)

    if minute < 15 {
        minute = 15
    } else if minute < 30 {
        minute = 30
    } else if minute < 45 {
        minute = 45
    } else {
        minute = 0
    }

    var hourQuarterDate = Calendar.current.nextDate(after: currentDate, …
Run Code Online (Sandbox Code Playgroud)

formatting date nsdateformatter nsdatecomponents swift3

3
推荐指数
1
解决办法
1819
查看次数

基于百分比的Android布局

我试图围绕Android布局,我想我会从一个简单的例子开始,但由于某种原因它不起作用.

我开始只是将布局划分为4个块,并使用背景颜色来证明它按预期工作.

这段代码很适合:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.25"
        android:background="@android:color/holo_green_light">
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.25"
        android:background="@android:color/white">
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.25"
        android:background="@android:color/holo_orange_light">
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.25"
        android:background="@android:color/holo_red_light">
    </RelativeLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

因此,我希望继续细分这些部分,并在第二部分上添加两个新布局,每个布局填充50%(有效地覆盖它).

我已尝试过LinearLayout和RelativeLayout,但我无法使用任何东西.

这是我现在的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.25"
        android:background="@android:color/holo_green_light">
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.25"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:background="@android:color/holo_green_dark"
            android:layout_alignParentLeft="true" >
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:background="@android:color/holo_blue_dark"
            android:layout_alignParentRight="true" >
        </LinearLayout>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.25" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

2
推荐指数
1
解决办法
148
查看次数

转换列表,过滤掉导致异常的项目

如何转换这个字符串数组:

"2018-05-08T23:22:49Z" "n/a" "2018-05-07T16:37:00Z"

使用高阶函数(例如map,flatMapreduce?)转换为日期数组

我确实知道可以使用 来做到这一点forEach,但我有兴趣涉及 Kotlin 高阶函数:

val stringArray
        = mutableListOf("2018-05-08T23:22:49Z", "n/a", "2018-05-07T16:37:00Z")

val dateArray = mutableListOf<Date>()

stringArray.forEach {
    try {
        val date = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US)
                .parse(it)
        dateArray.add(date)
    } catch (e: ParseException) {
        //* Just prevents app from crash */
    }
}
Run Code Online (Sandbox Code Playgroud)

reduce higher-order-functions kotlin

2
推荐指数
1
解决办法
1680
查看次数

返回活动之间的共享元素转换

我使用原生 Android Transition API 来制作 Activity 之间的过渡动​​画。这是我用来启动活动的来源:

        Intent intent = new Intent(MainActivity.this, DetailActivity.class);
        Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, imageView, imageView.getTransitionName()).toBundle();

        MainActivity.this.startActivity(intent, bundle);
Run Code Online (Sandbox Code Playgroud)

当我点击硬件后退按钮时,它会以预期的反向过渡动画返回到上一个活动,但是当我点击工具栏中的“向上”按钮时,它会以默认动画返回到上一个活动:

animation android android-animation android-transitions shared-element-transition

1
推荐指数
1
解决办法
1924
查看次数

1
推荐指数
1
解决办法
437
查看次数