【问题标题】:Textview in Android can only display two lines of text within RelativeLayoutAndroid中的Textview在RelativeLayout内只能显示两行文字
【发布时间】:2014-12-10 08:39:36
【问题描述】:

我正在 android 中创建一个聊天应用程序。我在我的设计部分使用 ListView 设计我的聊天布局我正在使用 RelativeLayout 作为聊天界面,但是如果我使用 9patch 气泡背景,消息文本只能显示两行文本,如果我删除它可以显示三行文本9patch 气泡背景。下面是我的xml文件。为什么它不能显示所有文本?还有一件事我想要右边的聊天时间,但是当消息文本到达一行或多行时它被隐藏了。感谢您的帮助。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/chat_wrapper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <LinearLayout
        android:id="@+id/chat_history"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@android:color/darker_gray" />

        <TextView
            android:id="@+id/date_section"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:text="02day12month"
            android:textSize="12sp" />

        <View
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@android:color/darker_gray" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/chat_view_left"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/chat_history">

        <TextView
            android:id="@+id/msg_chatter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/msg_text_left"
            android:text="Mr. Daroath" />

        <TextView
            android:id="@+id/msg_time_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/msg_text_left"
            android:layout_below="@+id/msg_text_left"
            android:layout_marginTop="2dp"
            android:text="10:20"
            android:textColor="#808080"
            android:textSize="12sp" />

        <ImageView
            android:id="@+id/reciever_profile_pic"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/msg_text_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/reciever_profile_pic"
            android:layout_toRightOf="@+id/reciever_profile_pic"
            android:text="Chat bubble is bubble in comic book that contains character's words. Some people call it speech bubble. Android app like eBuddy uses it when you are chatting with your friend."

            android:textSize="14sp" /><!-- android:background="@drawable/partner" -->
    </RelativeLayout>

</RelativeLayout>

【问题讨论】:

    标签: android xml layout chat android-relativelayout


    【解决方案1】:

    在相对布局中使用 android:layout_width="fill_parent"。试试这个

    【讨论】:

      【解决方案2】:

      乍一看(可能还有更多问题):您将 msg_time_left 与 msg_text_left 对齐,但稍后定义。这通常不适用于相对布局。始终确保在对齐时使用 id 引用,而不是 android:layout_alignRight="@+id/msg_text_left" 您应该使用 android:layout_alignRight="@id/msg_text_left"。这将在您的情况下失败,因为 ID 是稍后定义的。

      【讨论】:

        【解决方案3】:

        最后我做了一些改变,现在它可以工作了。无论如何,如果您有任何更好的设计理念,不胜感激!

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/chat_wrapper"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" >
        
            <LinearLayout
                android:id="@+id/chat_history"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
        
                <View
                    android:layout_width="0dp"
                    android:layout_height="1dp"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:background="@android:color/darker_gray" />
        
                <TextView
                    android:id="@+id/date_section"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:gravity="center_vertical"
                    android:text="02day12month"
                    android:textSize="12sp" />
        
                <View
                    android:layout_width="0dp"
                    android:layout_height="1dp"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:background="@android:color/darker_gray" />
            </LinearLayout>
        
            <LinearLayout
                android:id="@+id/text_wrap"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/chat_history"
                android:orientation="horizontal" >
        
                <ImageView
                    android:id="@+id/reciever_profile_pic"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_gravity="bottom"
                    android:src="@drawable/ic_launcher" />
        
                <RelativeLayout
                    android:id="@+id/chat_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="3dp" >
        
                    <TextView
                        android:id="@+id/msg_time"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="10:20"
                        android:layout_alignRight="@id/msg_text"
                        android:textColor="#808080"
                        android:textSize="12sp" />
        
                    <TextView
                        android:id="@+id/msg_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="@drawable/partner"
                        android:text="Chat bubble is bubble in comic book that contains character&apos;s words. Some people call it speech bubble. Android app like eBuddy uses it when you are chatting with your friend."
                        android:textSize="14sp"
                        android:layout_below="@id/msg_time" />
                </RelativeLayout>
            </LinearLayout>
        
            <TextView
                android:id="@+id/msg_chatter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/text_wrap"
                android:text="Mr. Daroath" />
        
        </RelativeLayout>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-11-02
          • 1970-01-01
          • 2018-07-07
          • 2014-08-24
          • 2016-08-25
          • 1970-01-01
          相关资源
          最近更新 更多