RelativeLayout Rechts

  • 4 Antworten
  • Letztes Antwortdatum
B

Binbose

Ambitioniertes Mitglied
0
Hallo Leute,
für einen kleinen Chat möchte ich, dass meine Sprechblasen rechts sind, bekomme es aber mit einem RelativeLayout einfach nicht hin. Hier ist das Sprechblasen Layout:
HTML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sprechblasenlayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:background="@drawable/speech_bubble_green"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Peter"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/tvZeitstempel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/message_text"
        android:layout_toRightOf="@+id/message_text"
        android:text="14:32"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/message_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tvName"
        android:layout_below="@+id/tvName"
        android:layout_margin="4dip"
        android:shadowDx="1"
        android:shadowDy="1"
        android:text="Medium Text"
        android:textSize="20sp" />

</RelativeLayout>

Und hier meine getView() Methode, ich habe da schon alles mögliche versucht, deshalb ist es ein bisschen unaufgeräumt:
Code:
public View getView(int position, View convertView, ViewGroup parent) {
              LayoutInflater inflater = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View listenEintrag = inflater.inflate(R.layout.chat_listeneintrag, parent, false); 
              
              DataModelNachricht message = (DataModelNachricht) values.get(position);
              RelativeLayout sprechblase = (RelativeLayout)listenEintrag.findViewById(R.id.sprechblasenlayout);
              
              TextView Nachricht = (TextView) listenEintrag.findViewById(R.id.message_text);
              Nachricht.setText(message.getNachricht());
              
              TextView Name = (TextView)listenEintrag.findViewById(R.id.tvName);
              Name.setText(message.getAbsender());
              
              TextView Zeitstempel = (TextView)listenEintrag.findViewById(R.id.tvZeitstempel);
              Zeitstempel.setText(message.getZeitstempel());
              
              LayoutParams lp = (LayoutParams) sprechblase.getLayoutParams();
              
              if(message.getAbsenderID()== MeineID)
              {
              sprechblase.setBackgroundResource(R.drawable.speech_bubble_green);
              sprechblase.setGravity(Gravity.RIGHT);
              }
              //If not mine then it is from sender to show orange background and align to left
              else
              {
              sprechblase.setBackgroundResource(R.drawable.speech_bubble_orange);
              sprechblase.setGravity(Gravity.LEFT);
              }
              //sprechblase.setLayoutParams(lp);
              return listenEintrag;
              }

Ich hoffe ihr könnt mir helfen, danke schonmal im vorraus.

mfg
 
Hallo, schlage folgenden Code mal nach:

Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sprechblasenlayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:background="@drawable/speech_bubble_green"
    android:orientation="vertical" >

genauer gesagt:
Code:
 android:layout_width="[COLOR="Red"]wrap_content[/COLOR]"
android:layout_height="[COLOR="Red"]wrap_content[/COLOR]

Bin mir ziemlich sicher, dass dort der "Fehler"...
Btw: warum hast du dich für ein RelativeLayout entschieden?

Hab deinen Code mal auf die schnelle korrigiert... Ist noch lange nicht "optimal", aber damit solltest du jedenfalls erstmal weitermachen können..

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/sprechblasenlayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="right"
                android:background="@drawable/speech_bubble_green"
                android:orientation="vertical" >

    <TextView
        android:id="@+id/tvName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Peter"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/tvZeitstempel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/message_text"
        android:layout_toRightOf="@+id/message_text"
        android:text="14:32"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/message_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_below="@+id/tvName"
        android:layout_margin="4dip"
        android:shadowDx="1"
        android:shadowDy="1"
        android:text="Medium Text"
        android:textSize="20sp" />

</LinearLayout>
 
Zuletzt bearbeitet:
Ja, beim LinearLayout müsste ich da match_parent nehmen, aber wenn ich das beim RelativeLayout versuche dann füllt die Sprechblase immer die ganze Breite
RelativeLayout habe ich einfach genommen um die TextViews leichter anordnen zu können, und weil es ja performanter ist (was aber wahrscheinlich kaum ins Gewicht fällt)
 
Was ist listenEintrag für ein Layout?
 
Das ist die XML Datei die ich dazu geschrieben habe.
Aber ich habs jetzt auch hinbekommen, mit nem LinearLayout drumrum und dann mit LayoutParams
 
Zurück
Oben Unten