レイアウトがあります
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@drawable/chat_bg">
<ImageView
android:id="@+id/avatar"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_marginRight="4dip"
android:src="@drawable/avatar_1_1"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5sp"
/>
</LinearLayout>
そして私が持っているJavaコードで:
LayoutParams lp1 = (LayoutParams) textView.getLayoutParams();
LayoutParams lp2 = (LayoutParams) avatarView.getLayoutParams();
if (incoming) {
lp1.gravity = Gravity.LEFT;
lp2.gravity = Gravity.LEFT;
textView.setBackgroundResource(R.drawable.speech_bubble_green);
textView.setLayoutParams(lp1);
avatarView.setLayoutParams(lp2);
} else {
lp1.gravity = Gravity.RIGHT;
lp2.gravity = Gravity.RIGHT;
textView.setBackgroundResource(R.drawable.speech_bubble_orange);
textView.setLayoutParams(lp1);
avatarView.setLayoutParams(lp2);
}
受信メッセージとそのアバターがViber のように右に配置され、左に送信されますが、すべてのメッセージは左に配置されます
すべての提案に感謝します