【发布时间】:2012-09-15 05:23:26
【问题描述】:
我正在尝试为聊天室构建对话泡泡。每个对话气泡都有附加的 xml 布局。
我通过将 textView 设置为 wrap_content、将语音气泡 imageView 设置为 match_parent 和frame_layout 到 wrap_content。这样文本后面的 speech_bubble 图像会根据气泡中的文本量进行缩放。
我将 textView 上的宽度设置为与父级匹配,并将高度设置为 wrap_content,出于某种原因,它完美地工作,符合 Ice Cream Sandwich 的要求(Android 4.1) . 然而,在 Gingerbread 中,内部 imageView 语音气泡不会缩放到 match_parent,因此文本可以整齐地放入气泡内。 在 Gingerbread 中,内部的 imageView 始终保持相同的大小,无论文本和 文本溢出气泡外。 尽管 frameLayout 扩展为 wrap_content,但 imageView 并没有像应有的那样 match_parent。
关于为什么会发生这种情况的任何想法?我可以通过 xml 设置另一个参数还是可以以编程方式调用来解决此问题的方法?
谢谢!
ICS 中的正确行为:
GingerBread 中的错误行为: Incorrect Behavior in GingerBread
XML 布局:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/speech_bubble_framelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/color_transparent"
android:layout_toRightOf="@id/message_user_imageView">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/message_background_imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:textColor="@color/color_brown_mud"
android:background="@drawable/chat_bubble_flipped"
/>
<TextView
android:id="@+id/message_textView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:maxEms="10"
android:background="@color/color_transparent"
android:textColor="@color/color_brown_uiDesign_pallete"
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:text="Message"
android:padding="5dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="20dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
/>
</FrameLayout>
</merge>
【问题讨论】:
标签: android android-layout android-fragments android-imageview android-listfragment