Bal*_*ala 8 android android-layout android-imageview android-fragments android-listfragment
我正在尝试为聊天室建立一个讲话泡泡.每个语音气泡都有附加的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中的行为不正确: 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>
Run Code Online (Sandbox Code Playgroud)
Xon*_*ono 25
从它的外观来看,这是由你的大小中的循环依赖引起的:内部文本和图像大小取决于FrameLayout(match_parent),而FrameLayout的大小取决于它内部包含的内容(wrap_content).如果出于这种原因涉及多个孩子,则不鼓励使用FrameLayout.为安全起见,我建议将内容更改FrameLayout为a RelativeLayout,并在内部图像视图上设置以下属性:
android:layout_alignTop="@+id/message_textview"
android:layout_alignBottom="@+id/message_textview"
Run Code Online (Sandbox Code Playgroud)
这样可以确保您的图片始终与文字大小相符.