イメージを左に、別のイメージを右に、次に右にイメージを含むレイアウトを作成しようとしています中央のレイアウトには、いくつかのTextViewが含まれています。Android - イメージの端とテキストの幅を可変にする方法
いずれかのTextViewの長さが十分短い場合は、全体の吹き出しがテキストを表示するのに十分な幅になるようにします。もしそれが長すぎるなら、私はそれを '...'でトリミングします。ここで
は、私は(私は明確にするため、すべてのマージンやパディングなどを取り除かました)を扱っていますXMLのサンプルです:
<RelativeLayout android:id="@+id/callout"
android:layout_width="wrap_content"
android:layout_height="54dp">
<ImageView android:id="@+id/callout_img_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RelativeLayout android:id="@+id/callout_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/callout_img_left">
<TextView android:id="@+id/callout_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true" />
<TextView android:id="@+id/callout_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:layout_below="@id/callout_name" />
</RelativeLayout>
<ImageView android:id="@+id/callout_img_right"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/callout_info"/>
</RelativeLayout>
は、もともと私はandroid:layout_alignParentRight="true"
を使用して右の画像があったが、これにより、全体のコールアウトが使用可能な幅になりました。上に示したXMLは短いテキストでは機能しますが、テキストが長すぎると、右側のイメージが押し出されます(縮小されます)。
私は実際にそれを試しましたが、うまくいきませんでした。上の私の例と同じ問題は、右の画像ビューが押されるまでテキストビューが水平方向に伸びるだけです。次に、省略記号を追加します。 –
@MickByrne - ああ。私は今問題を理解している。私は答えにレイアウトを変更しました(私が望む)これに対処します。 –
ありがとう! 'android:layout_weight =" 1 "'はすべて必要でした。 –