写消息时的动态大小 textview nativescript [英] dynamic size textview nativescript when you are writing a message

查看:19
本文介绍了写消息时的动态大小 textview nativescript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 angular2 在 nativescript 中创建了一个类似 whatsapp 的消息服务,当您在 android 平台中编写消息时,我遇到了 textview 的大小(高度)问题.当您添加另一行(如 whatsapp 或 facebook 等)时,我希望高度增加.

I make a messagerie service like whatsapp in nativescript with angular2 and i have a issue with the size(height) of the textview when you are writing a message in the android platform. i want the height increase when you add an other line (like whatsapp or facebook, etc).

在IOS中,这很简单.点击链接

In IOS, it's simple. click on the link

IOS 中文本视图的动态大小

我的 html 模板是(就在屏幕底部):

my html template is (just the bottom of the screen) :

<StackLayout class="message-box-container">
            <GridLayout columns="auto, *, auto"
                        class="message-box">
                <Label col="0"
                       class="fa link"
                       [text]="'fa-link' | fonticon">
                </Label>
                <GridLayout columns="auto, *"
                            col="1"
                            class="message-box-field">
                    <TextView #newMessage
                              col="0"
                              editable="true"
                              hint="Write a message..."
                              textWrap="true"
                              [(ngModel)]="newMessage.text"
                              (ngModelChange)="textChanged()"
                              [style.height]="textHeight"
                              class="write-message-field"></TextView>
                    <Label (tap)="sendMessage()"
                           col="1"
                           class="fa arrow"
                           [text]="'fa-arrow-circle-up' | fonticon">
                    </Label>
                </GridLayout>
            </GridLayout>
        </StackLayout>

用于更改,当您在 IOS 中输入时文本视图的大小:

for changing, the size of a textview when you are typing in IOS:

 textChanged() {
        if (isIOS) {
            this.textHeight = this.newMessage.ios.contentSize.height;
        } else{//ANDROID TODO}

推荐答案

它比你想象的要容易得多,只是不要将 height 设置为 TextView/set它auto,所以它会增长到需要的高度.

It's much more easier than you think, just don't set a height to TextView / set it to auto so it grows till as much height is requires.

这篇关于写消息时的动态大小 textview nativescript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆