2012-06-16 21 views
6

Ich versuche, ein ImageView mit 4 textView anzuzeigen. "Titel" "Zeiten" "Alter" und "Informationen". Alle von ihnen sind im globalen horizontalen Layout. Und die 4 TextView sind in einem vertikalen Layout. Die Sache ist, dass ich "Zeiten" und "Alter" in derselben Zeile haben möchte. Aber es kann nicht mit einem vertikalen Layout sein. Hier ist mein xml-Code:Wie kann ich zwei TextView auf einer Linie in einem vertikalen Layout platzieren

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 
<ImageView 
    android:id="@+id/imgLink" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_launcher" /> 



<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <TextView 
    android:id="@+id/title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Titre" 
    android:textSize="8sp" 
    android:textStyle="bold" /> 

    <TextView 
    android:id="@+id/time" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="8sp" 
    android:text="age" /> 


    <TextView 
    android:id="@+id/age" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="8sp" 
    android:text="age" /> 

    <TextView 
    android:id="@+id/information" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ellipsize="end" 
    android:textSize="8sp" 
    android:text="phrase" /> 

</LinearLayout> 

Dank

+0

Warum kann nicht eine weitere LinearLayout mit Android: Orientation = "horizontal" oder relative Layuot? –

+0

@DheereshSingh Wenn Sie die Breite des übergeordneten Elements überschreiten, wird es nicht in die nächste Zeile umgebrochen. –

Antwort

4

Hier gehen Sie

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/imgLink" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Titre" 
      android:textSize="8sp" 
      android:textStyle="bold" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/time" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Time" 
       android:textSize="8sp" /> 

      <TextView 
       android:id="@+id/age" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:text="age" 
       android:textSize="8sp" /> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/information" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="end" 
      android:text="phrase" 
      android:textSize="8sp" /> 
    </LinearLayout> 
+0

vielen dank, es funktioniert. :) – dracraft

+0

Gern geschehen :) –

1

LinearLayout als Eltern Put auf beiden Textviews und setzte Orientierung dieses Linearlayouts als Horizontal ..

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

<TextView 
    android:id="@+id/time" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="8sp" 
    android:text="time" /> 
<TextView 
    android:id="@+id/age" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="8sp" 
    android:text="age" /> 

<LinearLayout/> 
+0

Ich habe 3 lineare Layouts ähnlich zu diesem in einem linearen Layout mit vertikaler Ausrichtung. Ist es möglich, diese im Fall Textviews unterschiedlicher Breite in jedem Layout auszurichten. – Anuj

0

wie ich es einen weiteren Ansatz Relative Layout einer der zweiten

<TextView 
android:id="@+id/title" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Title" 
android:textSize="8sp" 
android:textStyle="bold" 
android:layout_alignParentTop="true" /> 

<TextView 
android:id="@+id/time" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="8sp" 
android:text="time" 
android:layout_below="@id/title" /> 


<TextView 
android:id="@+id/age" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:textSize="8sp" 
android:text="age" 
android:layout_below="@id/title" 
android:layout_toRightOf="@id/time" /> 

<TextView 
android:id="@+id/information" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:ellipsize="end" 
android:textSize="8sp" 
android:text="phrase" 
android:layout_below="@id/time" /> 

gesagt ist
0

Verwenden Sie das grafische Layout, und legen Sie das Alter und die Zeit Felder auf der gleichen Ligne..much einfacher

Verwandte Themen