I have a very interesting problem. I should make a layout for a text message like in telegram, but only with text. So i should shift timestamp a little bit down if text of message take more than 1 lines. I made layout with 2 textViews (one for single line message and other for multiline, you can see my layout in attach)
My problem is that when i show timestamp for multiline case all list a little jump (because height of view change) Here my code from my viewHolder (i use kotlin, but it still very obvious). The main question is - how i can calculate line count in textView before render?
val date = stamp.toString(Constants.DEFAULT_TIME_FORMAT)
textViewItemMessageText.text = text
textViewItemMessageTimeForSingleLine.show()
textViewItemMessageTime.hide()
textViewItemMessageTimeForSingleLine.text = date
textViewItemMessageText.post {
if (textViewItemMessageText.lineCount > 1) {
textViewItemMessageTimeForSingleLine.hide()
textViewItemMessageTime.show()
textViewItemMessageTime.text = date
}
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_marginBottom="4dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="20dp"
android:layout_marginTop="4dp"
app:cardBackgroundColor="@color/thin_green"
app:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textViewItemMessageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:textColor="@color/black_light_87"
android:textSize="14sp"
android:textStyle="normal"
tools:text="My generation"/>
<TextView
android:id="@+id/textViewItemMessageTimeForSingleLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:drawableLeft="@drawable/ic_read"
android:fontFamily="sans-serif"
android:gravity="center_vertical"
android:textColor="@color/grass_two_54"
android:textSize="12sp"
android:textStyle="normal"
tools:text="16:20"/>
</LinearLayout>
<TextView
android:id="@+id/textViewItemMessageTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginLeft="4dp"
android:layout_marginTop="2dp"
android:drawableLeft="@drawable/ic_read"
android:fontFamily="sans-serif"
android:textColor="@color/grass_two_54"
android:textSize="12sp"
android:textStyle="normal"
tools:text="16:20"/>
</LinearLayout>
</android.support.v7.widget.CardView>