1

水平方向の LinearLayout を wrap_content に設定しています。内部には、複数の行 (wrap_content も) と ImageButton (wrap_content) を許可する単一の TextView を含む垂直 LinearLayout があります。いくつかのコンポーネントにはマージンとパディングがあり、スペースが適切に配置されています。

TextView 内のテキストが短い場合、すべて問題ありません。テキストが複数行に折り返されても問題ありません。テキストが折り返すのに十分な長さになると、ImageButton は水平方向に切り取られます。つまり、左側と右側が切り取られます。マージンとパディングを引き出すとうまくいきますが、もちろん見た目は良くありません。

私の推測では、レイアウト システムはマージンとパディングの一部を考慮せずにテキストの幅を計算していると思われます。次に、物事をレイアウトし、TextView の最初のパスよりも総スペースが少ないため、レイアウトの 2 番目の項目をクリッピングし、計算された TextView の幅を尊重します。しかし、それは単なる推測です。

私自身のレイアウトを書くことはできませんが、何かアイデアはありますか?

編集

これは、階層ビューアーのスクリーン ショットで、ImageButton がクリップされている場所と、関連する XML が強調表示されていることを示しています。ImageButton の境界は、私が見ているものと一致しています: 27 dp 幅ですが、円の画像自体は実際には 36 dp 幅であり、ImageButton には両側に 4 dp のパディングが指定されています。

階層ビューアのスクリーン ショット

繰り返しになりますが、そのテキストは慎重に選択する必要がありました。短くてもボタンは問題ありません。長くするとラップし、ボタンは再び正常になります。

編集

そして、ここに私のXMLがあります:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/messageBubble"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minHeight="@dimen/message_bubble_min_height"
        android:layout_alignTop="@id/avatar"
        android:layout_alignLeft="@id/avatar"
        android:layout_marginTop="@dimen/message_bubble_margin_top"
        android:layout_marginLeft="@dimen/message_bubble_inset"
        android:layout_marginRight="@dimen/message_inbound_padding_inside"
        android:paddingLeft="@dimen/message_bubble_padding_outside"
        android:paddingRight="@dimen/message_bubble_padding_inside"
        android:paddingTop="@dimen/message_bubble_padding_v"
        android:paddingBottom="@dimen/message_bubble_padding_v"
        android:orientation="horizontal">

    <LinearLayout
            android:id="@+id/contentContainer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:orientation="vertical">
        <TextView
                android:id="@+id/messageBody"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/message_body_margin_outside"
                android:layout_marginRight="@dimen/message_body_margin_inside"
                android:layout_marginTop="@dimen/message_body_margin_v"
                android:layout_marginBottom="@dimen/message_body_margin_v"
                android:gravity="left"
                android:autoLink="all"
                android:textSize="17dp" />
    </LinearLayout>

    <include layout="@layout/view_message_action_btn" />

</LinearLayout>

含まれている view_message_action_btn:

<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/actionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
    android:src="@drawable/action_btn"
    android:paddingLeft="@dimen/message_action_btn_padding_h"
    android:paddingRight="@dimen/message_action_btn_padding_h" />
4

0 に答える 0