大学のコースのインスタントメッセージアプリケーションを開発しています.WithSappに似ていますが、添付のスクリーンショットのアイコンを見れば分かるはずです。RelativeLayoutのTextViewを正しく整列する
私はListFragmentにカスタムCursorAdapterを取り込みました。 2つのタイプのビュー、送信メッセージ(右揃え)、受信メッセージ(左揃え)を提供します。
送信されたメッセージのレイアウトはうまく動作しますが、受信したメッセージについても同じことを言うことはできません。ここで
はスクリーンショットです:
送信されたメッセージのレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#FFCCCCCC"
android:padding="5dp" >
<TextView
android:id="@+id/ceo_timestamp"
android:layout_width="60sp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#FFBBBBBB"
android:gravity="center"
android:textSize="10sp" />
<TextView
android:id="@+id/ceo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ceo_timestamp"
android:background="#FFAAAAAA"
android:gravity="right"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
受信したメッセージのレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#FF999999"
android:padding="5dp" >
<TextView
android:id="@+id/cei_timestamp"
android:layout_width="60sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#FF888888"
android:gravity="center"
android:textSize="10sp" />
<TextView
android:id="@+id/cei_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/cei_timestamp"
android:background="#FF777777"
android:gravity="right"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
これらの醜い背景色がちょうど見に追加されます各ビューとレイアウトに必要なスペース。あなたがスクリーンショットで見ることができるように、メッセージの送信(右揃え)は素晴らしい仕事です。受信したメッセージ(左詰め)はうまく整列していません。なぜなら、RelativeLayoutはコンテンツをラップするだけで、すべての水平スペースを利用できるからです。
誰でもどのように修正するか、または私が必要なものを達成するためのより良いレイアウト設計を知っていますか?
ありがとうございます。
+1を撮影しています...:) – Farhan
これらのばかげたものとコーヒーは、仕事があり時間が足りない時にはついていくのがいいです:) – mavnaranjo
あなたのスクリーンショットは+1です。 – PhatHV