【问题标题】:android listview apperence like whats app Listview for chat applicationandroid listview 外观,如聊天应用程序的 whatsapp Listview
【发布时间】:2014-12-12 12:38:22
【问题描述】:

您好,我需要在聊天屏幕中开发类似 这样的应用程序的布局 在此我想在聊天 textview 完成后显示时间。

我已经做到了

<RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/blue" >

                <TextView
                    android:id="@+id/tv_message_chat_item_f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2dp"
                    android:layout_marginTop="2dp"
                    android:gravity="left|center"

                    android:paddingBottom="@dimen/one_dp"
                    android:paddingLeft="@dimen/fifteen_dp"
                    android:paddingRight="@dimen/five_dp"
                    android:paddingTop="@dimen/one_dp"
                      android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="fgfdgdf rete tretretret rtrtrwtw fgdfr grtwerwerewr ewrwerew" />

                <TextView
                    android:id="@+id/tv_message_time_f"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_below="@+id/tv_message_chat_item_f"
                    android:layout_marginBottom="2dp"
                   android:paddingRight="@dimen/five_dp"
                    android:gravity="right"
                    android:paddingBottom="@dimen/one_dp"
                    android:text="fgfdg"
                    android:textAppearance="?android:attr/textAppearanceSmall" />



            </RelativeLayout>

但不能处理大消息(texview 的时间设置不正确)

【问题讨论】:

  • 使用 javapapers 教程:javapapers.com/android/android-chat-bubble
  • 是的,我可以设置消息文本视图,但问题是什么时候,当我像上面的屏幕截图一样输入日期/时间时
  • 正确使用重力或使用框架布局作为父布局,然后放置,时间始终正确。
  • 我用过喜欢看编辑的阙。但我需要它,就像精确的屏幕截图一样,意味着当小消息时,相对布局必须像屏幕截图一样精确的宽度
  • 或查看您的whatsapp。发送像 hi 这样的小消息并发送 3 4 行的消息,看看区别

标签: android layout


【解决方案1】:
<LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:gravity="bottom"
        android:background="@drawable/blue"
        android:layout_alignParentStart="true" android:weightSum="10">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Hi"
            android:layout_weight="1"
            android:id="@+id/textView"
            android:gravity="bottom"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="bottom"
            android:layout_marginStart="10dp"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </LinearLayout>

【讨论】:

    【解决方案2】:

    假设您的 textView3 是带有“重要信息”的那个,您应该首先利用相对布局功能并使用 android:layout_below="@id/textview2" 这将防止与 textView2 重叠,而不仅仅是从下往上对齐所有内容。

      <TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/textView2"
                    android:layout_centerHorizontal="true"
                    android:text="Small Text"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
    

    那么在你设置了你的TextView 之后,你就可以使用类似的东西了

       <TextView
                        android:id="@+id/textView3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/textView2"
                        android:gravity="right"
                        android:layout_alignParentRight="true"
                        android:text="12:00 pm"
                        android:textAppearance="?android:attr/textAppearanceSmall" />
    

    Gravity right 将允许从右到左放置文本,因为显示时间通常不会超过 6 或 7 个字符,这会有所帮助。

    希望它能解决您的问题。

    【讨论】:

      【解决方案3】:

      您将需要使用 9 个补丁来实现 ImageViews(此处:link) 还有一个列表视图,它可以处理 ListItems 的 CustomLayouts(使用 9Patch ImageView)。

      我认为您能够实现列表视图,因此我不会在这里深入。 问候。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-17
        • 2017-04-19
        • 1970-01-01
        • 1970-01-01
        • 2018-06-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多