小编cha*_*ary的帖子

如何将UICollectionView的高度调整为UICollectionView的内容大小的高度?

我想UICollectionView(红色的)缩小到内容大小的高度,在这种情况下UICollectionViewCells(黄色的)因为有很多空的空间.我尝试的是使用:

override func layoutSubviews() {
    super.layoutSubviews()
    if !__CGSizeEqualToSize(bounds.size, self.intrinsicContentSize) {
        self.invalidateIntrinsicContentSize()
    }
}

override var intrinsicContentSize: CGSize {
    return self.collection.contentSize
}
Run Code Online (Sandbox Code Playgroud)

return self.collection.contentSize总是返回(宽度,0),因此它收缩到高度值30(我在xib文件中为高度设置的值,虽然我有constaint> = 30).

在此输入图像描述

ios swift

54
推荐指数
8
解决办法
6万
查看次数

React Native中的fetch未定义错误

我试图在我的项目中使用fetch但是有一个错误说

fetch未定义

在此输入图像描述

有人知道为什么吗?

react-native

7
推荐指数
2
解决办法
9009
查看次数

无法启动离子2空白项目

我正在尝试启动一个离子2空白项目,但它总是创建一个离子1项目.我就是做这个的:

npm install -g ionic@beta
ionic start Test --v2
Run Code Online (Sandbox Code Playgroud)

但是当我打开项目时,它仍然是版本1.我试图用以下方法完全去除离子:

sudo npm uninstall -g ionic
sudo npm uninstall -g ionic@beta
sudo npm uninstall -g cordova
Run Code Online (Sandbox Code Playgroud)

但在那之后,当我键入"离子"时,它表明我有离子v1.7.14.(做了好几次,没有任何错误).

ionic-framework ionic2

6
推荐指数
2
解决办法
6370
查看次数

使用数据绑定加载图像

我想使用 Android 数据绑定设置图像。我已经阅读了很多关于此的教程,但图像仍然没有出现。

在我的模型中,我有以下方法:

@BindingAdapter({"app:imageUrl"})
    public static void loadImage(ImageView view, String url) {

        Log.i("III", "Image - " + url);
        Context context = view.getContext();
        Glide.with(context).load(GlobalValues.img_start_url + url).into(view);
    }
Run Code Online (Sandbox Code Playgroud)

我还应该提到“III”、“Image -” + url 永远不会打印,所以问题不在于 Glide。

这是我的 xml:

 <data>

    <variable
        name="feeling"
        type="bg.web3.helpkarma.ViewModels.Feeling"/>

</data>

<ImageView
            android:layout_width="wrap_content"
            android:id="@+id/icon"
            android:layout_height="wrap_content"
            android:layout_marginRight="16dp"
            app:imageUrl="@{feeling.maleIcon}"/>
Run Code Online (Sandbox Code Playgroud)

并且maleIcon 是一个url 字符串

@SerializedName("male_icon")
@Expose
private String maleIcon;
Run Code Online (Sandbox Code Playgroud)

android android-databinding

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

带有 React Native 的 Google Cloud 语音

我正在尝试使用 Google Cloud Speech API,因此我可以传递音频文件并接收翻译的文本,但我坚持集成。我已经有了 api 密钥和所需的一切,但无法从 react native 中找到如何使用它。在文档中只有 node.js 的解释(来自 javascript 部分)。还有几个库已经过时或仅支持一个操作系统。有人成功了吗?

文档中的 node.js 示例:

// Imports the Google Cloud client library
const Speech = require('@google-cloud/speech');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Instantiates a client
const speechClient = Speech({
  projectId: projectId
});

// The name of the audio file to transcribe
const fileName = './resources/audio.raw';

// The audio file's encoding and sample rate
const options = {
  encoding: 'LINEAR16',
  sampleRate: 16000
}; …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native google-cloud-speech

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

像 Twitter 一样显示时间之前

DateUtils.getRelativeTimeSpanString()用于在发布帖子时显示。

它返回的字符串是这样的:1 minute ago,但我想要1 m1 h等等(缩短并且没有之前)。

我可以用“h”替换“hour”或用“m”替换“minute”,但如果语言与英语不同,它将不起作用。这就是现在Twitter正在使用的。Twitter 的英文/西里尔文显示方式。

在此处输入图片说明

在此处输入图片说明

更新:我会接受@Bradley Wilson 的回答,尽管我会在这里添加更清洁的解决方案(再次使用 JodaTime 包)。此外,其余的答案也可以修改为相同的结果,因此他们值得投票。谢谢你们:

    DateTime postMaded = new DateTime(your previous date);
    DateTime nowUpdate = new DateTime();

    Period period = new Period(postMaded, nowUpdate);

    PeriodFormatter formatter;

    Locale current = ConverterMethods.getCurrentLocale();

    if (current.getLanguage().contentEquals(any Cyrillic language )) {

        if (period.getYears() != 0) {
            formatter = new PeriodFormatterBuilder().appendYears().appendSuffix(" ?.").printZeroNever().toFormatter();
        } else if (period.getMonths() != 0) {
            formatter = new PeriodFormatterBuilder().appendMonths().appendSuffix(" ?").printZeroNever().toFormatter();
        } else …
Run Code Online (Sandbox Code Playgroud)

java time android java-time

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