8

チャットルーム用の吹き出しを作成しようとしています。各吹き出しには、添付のxmlレイアウトがあります。 

textViewwrap_contentに、吹き出しimageViewmatch_parentに、frame_layoutwrap_contentに設定することで、これを実現しています。テキストの背後にあるspeech_bubble画像 が、バブル内 のテキストの量に応じて拡大縮小されるようにします。

textViewの幅を親に一致するように設定し、高さをwrap_contentに設定しました。何らかの理由で、Ice Cream Sandwich(Android 4.1)で必要とされるように完全に機能します。ただし、Gingerbreadでは、テキストがバブル内にきちんと収まるように、内側のimageView吹き出しはmatch_parentにスケーリングされません。ジンジャーブレッドでは、テキストに関係なく、内側のimageViewは常に同じサイズのままであり、テキストはバブルの外側にオーバーフローします。frameLayoutがwrap_contentに展開されても、imageViewは想定どおりにmatch_parentではありません。 

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

ありがとう!

ICSでの正しい動作:

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

1 に答える 1

27

外見からすると、これはサイズの循環依存が原因です。内部のテキストと画像のサイズは FrameLayout に依存し ( match_parent)、FrameLayout のサイズはその中に含まれるものに依存します ( wrap_content)。まさにこのような理由で、複数の子が関係する場所では FrameLayout を使用しないことをお勧めします。安全のために、 を に変更し、内側の画像ビューで次のプロパティを設定することをお勧めしFrameLayoutますRelativeLayout

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

これにより、画像が常にテキストのサイズに一致するようになります。

于 2012-09-15T05:34:08.823 に答える