小编jaz*_*gil的帖子

ConstraintLayout:设置行中所有视图的高度以匹配最高的视图

我正在尝试使用ConstraintLayout(版本1.0.2)来设置2个并排视图的高度以匹配其中最高的一个.这用作RecyclerView的ViewHolder,其中每个TextView获取任意长度的文本......

如果我将每个设置为wrap_content,则较短的一个将缩小.如果我将两者都设置为0dp(match_contraints),则两者都以0高度结束.

这是设置:

<?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_marginLeft="2dp"
    android:layout_marginRight="2dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/id1"
        android:layout_width="60dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/id2"/>

    <TextView
        android:id="@+id/id2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@+id/id1"
        app:layout_constraintEnd_toEndOf="parent"/>

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

我想这是一个错误,因为"0dp"应该更像match_parent而不是实际的0 dp.

顺便说一下,在iOS上,等效的自动布局规则(设置视图的高度以匹配父级的顶部和底部)产生预期的结果.

当然使用LinearLayout非常简单,但是这个布局在更大的布局中起作用,我想修剪视图层次结构......

android android-constraintlayout

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

Firebase的云功能:序列化Promise

在onWrite处理程序中,我想执行多次读取,操作一些数据,然后存储它.我是Promise概念的新手.我对以下Promise处理是否安全,关于Firebase在完成之前没有查询我的查询?

exports.test = functions.database.ref('/zzz/{uid}').onWrite(event => {
    console.log('zzz', event.data.val());

    return Promise.all([
        admin.database().ref('/zzz/1').once('value'),
        admin.database().ref('/zzz/2').once('value')
    ]).then(function(snaps) {
        console.log('loaded', snaps[0].val());
        var updKeys = {
            ["/xxx/" +event.params.uid +"/zoo"]: 'giraffe',
        }

        admin.database().ref().update(updKeys, function(error) {
            console.log("Updating data finished. ", error || "Success.");
        })
    });

});
Run Code Online (Sandbox Code Playgroud)

以上作品,但不确定其正确的方式......

javascript firebase firebase-realtime-database google-cloud-functions

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

适用于Firebase的云功能:如何向我的Cloud Endpoint发出请求

我正在尝试在firebase数据库中写入某个值时向我的云端点项目发出请求.我找不到任何如何在Node.js中对端点执行请求的示例.这是我到目前为止所提出的:

"use strict";
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const gapi = require('googleapis');

admin.initializeApp(functions.config().firebase);

exports.doCalc = functions.database.ref('/users/{uid}/calc').onWrite(event => {
    return gapi.client.init({
            'apiKey': 'AIzxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            'clientId': '1234567890-xxx.apps.googleusercontent.com',
            'scope': 'donno what to put here'
       }).then(function() {
           return gapi.client.request({
               'path': 'https://myproj.appspot.com/_ah/api/myApi/v1',
               'params': {'query': 'startCalc', uid: event.params.uid }
           })
       }).then(function(response) {
           console.log(response.result);
       }, function(reason) {
           console.log('Error: ' + reason.result.error.message);
       });
});
Run Code Online (Sandbox Code Playgroud)

触发后,功能的日志喷口:TypeError: Cannot read property 'init' of undefined.即甚至不认识gapi.client.

首先,用于此请求的正确包装是什么?googleapis?请求承诺?

第二,我是否为端点调用设置了正确的路径和参数?假设端点功能是startCalc(int uid).

node.js firebase google-cloud-endpoints google-cloud-functions

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

如何将 websocket 连接(Node.js + ws)从端口 A 转发到端口 B?

假设我有一台在 8000 端口上运行的服务器,如下所示:

  var s = http.createServer();
  s.on('request', function(request, response) {
    response.writeHeader(200);
    response.end();
  });
  s.listen(8000);
  var w = new WebSocketServer({
    server: s
  });
Run Code Online (Sandbox Code Playgroud)

然后我希望将在端口 8000 上收到的消息转发到端口 9000:

w.on('connection', function(ws) {
  var remote = null;

  ws.on('message', function(data) {
    remote = new WebSocket('ws://127.0.0.1:9000');
    remote.on('open', function() {
      remote.send(data);
    });
  });
  ws.on('close', function() {
    if (remote) {
      return remote.destroy();
    }
  });
  return ws.on('error', function() {
    if (remote) {
      return remote.destroy();
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

可悲的是,这个实现似乎不起作用。这样做的正确方法是什么?

node.js

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