Android的ImageView的不里面的FrameLayout match_parent低于姜饼 [英] Android ImageView does not match_parent inside FrameLayout below GingerBread

查看:176
本文介绍了Android的ImageView的不里面的FrameLayout match_parent低于姜饼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个对​​话泡泡的聊天室。每个语音泡沫的具有附加的XML布局。

我通过设置实现这一目标的的TextView WRAP_CONTENT ,语音泡沫的ImageView match_parent frame_layout WRAP_CONTENT 。因此,根据文本的泡沫量后面的文本尺度speech_bubble图像。

我设置TextView的宽度符合家长和高度WRAP_CONTENT出于某种原因,它的完美的作品作为要求冰淇淋三明治(安卓4.1) 。 然而,在姜饼内ImageView的讲话泡沫的不能扩展到match_parent 使文本可以在里面泡完全满足需要。 在姜饼内ImageView的保持相同的尺寸总是,无论是文本和文字的泡沫外溢出。 即使在的FrameLayout 扩展到 WRAP_CONTENT ,在的ImageView match_parent 作为它应该。

这是为什么发生这种情况的任何想法?有另一种参数我可以设置直通XML或方法我可以调用编程方式解决这一问题?

谢谢!

在ICS正确的行为:

在ICS 正确行为

不正确的行为姜饼: 不正确的行为姜饼

XML布局:

 <合并的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
        <的FrameLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID / speech_bubble_framelayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:背景=@色/ color_transparent
机器人:layout_toRightOf =@ ID / message_user_imageView>

< ImageView的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@ + ID / message_background_imageview
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_margin =5DP
机器人:scaleType =fitXY
机器人:layout_centerInParent =真
机器人:文字颜色=@色/ color_brown_mud
机器人:背景=@可绘制/ chat_bubble_flipped
/>
<的TextView
机器人:ID =@ + ID / message_textView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =match_parent
机器人:maxEms =10
机器人:背景=@色/ color_transparent
机器人:文字颜色=@色/ color_brown_uiDesign_pallete
机器人:TEXTSIZE =15sp
机器人:TEXTSTYLE =黑体
机器人:重力=center_horizo​​ntal
机器人:文本=消息
机器人:填充=5DP
机器人:layout_marginLeft =25dp
机器人:layout_marginRight =20dp
机器人:layout_marginTop =15dp
机器人:layout_marginBottom =15dp
/>
< /的FrameLayout>
< /合并>
 

解决方案

从外观上来看,这是由于循环依赖于你的尺寸:内的文本和图像的大小取决于的FrameLayout(<为code> match_parent ),而的FrameLayout的大小取决于什么是包含在里面( WRAP_CONTENT )。使用的FrameLayout是不鼓励的,其中一个以上的孩子参与的正是这种原因。为了安全起见,我建议改变的FrameLayout RelativeLayout的,并设置以下属性在内部图像视图

 安卓layout_alignTop =@ + ID / message_textview
机器人:layout_alignBottom =@ + ID / message_textview
 

这将确保图像始终匹配到你的文字的大小。

I am trying to build a speech bubble for a chat room. Each of the speech bubbles has the attached xml layout. 

I am achieving this by setting the textView to wrap_content, the speech bubble imageView to match_parent and the frame_layout to wrap_content. So that the speech_bubble image behind the text scales according to the amount of text in the bubble. 

I set the width on the textView to match parent and the height to wrap_content and for some reason, it works perfectly as required in Ice Cream Sandwich (Android 4.1). However in Gingerbread the inner imageView speech bubble does not scale to match_parent so that the text can fit neatly inside the bubble.  In Gingerbread the inner imageView stays the same size always, regardless of the text and the text overflows outside the bubble.  Even though the frameLayout expands to wrap_content, the imageView does not match_parent as it is supposed to. 

Any ideas on why this is happening?  Is there another parameter I can set thru xml or a method I can call programmatically to fix this? 

Thanks!

Correct Behavior in ICS:

Correct Behavior in ICS

Incorrect Behavior in GingerBread: Incorrect Behavior in GingerBread

XML Layout :

<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>

解决方案

From the looks of it, this is caused by a circular dependency in your sizes: the inner text and image size is dependent on the FrameLayout (match_parent), while the FrameLayout's size is dependent on what's contained inside it (wrap_content). Use of a FrameLayout is discouraged where more than one child is involved for exactly this sort of reason. For safety, I'd recommend changing the FrameLayout to a RelativeLayout, and setting the following property on the inner image view:

android:layout_alignTop="@+id/message_textview"
android:layout_alignBottom="@+id/message_textview"

This will ensure your image always matches up to the size of your text.

这篇关于Android的ImageView的不里面的FrameLayout match_parent低于姜饼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆