写消息时的动态大小 textview nativescript

dynamic size textview nativescript when you are writing a message

我使用 angular2 在 nativescript 中制作了一个类似 whatsapp 的消息服务,当您在 android 平台上写消息时,我遇到了文本视图的大小(高度)问题。当你添加另一行时(比如 whatsapp 或 facebook 等),我希望高度增加。

在IOS中,很简单。点击 link

dynamic size of a textview in IOS

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

<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:

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

这比你想象的要容易得多,只是不要将 height 设置为 TextView / 将其设置为 auto 以便它增长到需要的高度。

动态文本视图高度。动态增加 textView 高度 它适用于 android 和 ios

<TextView height="auto" editable="true" hint="Write a message..." textWrap="true"[(ngModel)]="text" ></TextView>