したがって、私のテキストビューは画像ビューの上に描画する必要があるため、xml で次のように定義されます。
<ImageView
android:id="@+id/chatBalloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="@+id/chatItemProfPic"
android:scaleType="fitXY"
android:src="@drawable/chat_bar_user" />
<TextView
android:id="@+id/userText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="@+id/chatItemProfPic"
android:text="username"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
しかし、textView には複数行のテキストを含めることができるため、それに応じて imageView の高さを大きくする必要があります。これは、次のルールを追加することで実現できます。
android:layout_alignBottom="idOfText"
しかし、その部分で textView が定義されていないため、アプリがクラッシュします。ビューが描画される前にonCreateで呼び出すため、LayoutParamsのaddRuleでコードから実行しようとすると同じ結果になります。
これをバイパスする方法はありますか?
解決済み: 最終的な xml:
<ImageView
android:id="@+id/chatBalloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="@+id/chatItemProfPic"
android:scaleType="fitXY"
android:layout_alignBottom="@+id/userText"
android:src="@drawable/chat_bar_user" />
<TextView
android:id="@id/userText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:layout_toRightOf="@+id/chatItemProfPic"
android:text="username"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />