8

私はチャットルーム用のスピーチバブルを作成しようとしています。各スピーチバブルには添付されたxmlレイアウトがあります。AndroidのImageViewがGingerBreadの下のFrameLayout内のmatch_parentと一致しません

私はmatch_parentframe_layoutにwrap_contentのTextViewにwrap_content、吹き出しImageViewのを設定することでこれを実現しています。テキストの背後にあるspeech_bubbleイメージは、テキストの量に応じて縮尺が変わります。はバブルです。

私は親とwrap_contentする高さに合わせるのTextViewに幅を設定し、いくつかの理由で、それは、アイスクリームサンドイッチ(アンドロイド4.1)に必要に応じて完全にに動作します。 しかしジンジャーブレッド内側の画像ビューの泡はと一致しません。テキストは泡の中にきれいに収まります。 ジンジャーブレッドでは、内面画像の表示は、テキストに関係なく常にの同じサイズのままで、のテキストの外にはのテキストがあふれています。 でframeLayoutwrap_contentに展開されていても、それがすることになっているよう 、ImageViewのはないmatch_parentを行います。

これはなぜ起こっているのですか? xmlを使って設定できる別のパラメータがありますか、これを修正するためにプログラムで呼び出せるメソッドはありますか?

ありがとうございます! ICSで

正しい動作:ジンジャーブレッドで

Correct Behavior in ICS

誤った行動: 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> 

答えて

24

が、これはによって引き起こされますサイズの循環依存:内部テキストと画像のサイズはFrameLayoutに依存します( match_parent)、FrameLayoutのサイズは内部に含まれる内容(wrap_content)に依存します。 FrameLayoutの使用は、この種の理由で複数の子が関与する場合はお勧めできません。安全のために、私はRelativeLayoutFrameLayoutを変更すると、内側の画像ビューに次のプロパティを設定することをお勧めしたい:

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

これは、あなたのイメージは常に、あなたのテキストのサイズまで一致することを確認します。

+0

問題を修正しました。 alignBottomとalignRightをいくつかのパディングに使用しました。ありがとうございました! – Bala

関連する問題