2017-07-23 7 views
0

Ich zeige Daten in der Listenansicht. Ich möchte alle Namen in der gleichen Ausrichtung haben. Ich habe Gewicht verwendet, weil ich nicht möchte, dass das Bild den größten Teil des Bildschirms einnimmt. Aber auf diese Weise kann ich Bilder nicht auf die gleiche Weise ausrichten. So sieht es aus. image of pageAndroid - Gleiche Ausrichtung - Layout

Hier ist mein Code:

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


<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="48dp" 
    android:layout_height="48dp" 
    android:layout_gravity="center_vertical" 
    android:layout_weight="1" 
    android:paddingLeft="20dp" 
    android:scaleType="fitStart" 
    app:srcCompat="@drawable/food_icon" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_weight="3" 
    android:paddingLeft="0dp"> 

    <TextView 
     android:id="@+id/menu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="0dp" 
     android:text="TextView" 
     android:textSize="18sp" 
     android:textStyle="bold" /> 

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

     <TextView 
      android:id="@+id/cost" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="TextView" 
      android:textSize="14sp" /> 

     <TextView 
      android:id="@+id/owner" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="TextView" /> 

     </LinearLayout> 
     </LinearLayout> 

    </LinearLayout> 

Ich brauche Hilfe. Danke ...

+0

Warum haben Sie verschachtelt LinearLayouts wurde? Können Sie ein Beispiel veröffentlichen, wie es aussehen soll? – Nick

+0

android: gravity = "left" benutze das für den Menütext id –

+0

@Nick Das ist was ich eigentlich will aber auch ich will dass alle Namen bei gleicher Ausrichtung beginnen. Vielleicht kann ich es nicht auf Englisch erklären. Ich möchte, dass Namen in derselben X-Koordinate beginnen. Zum Beispiel suchen Joe und Stevekjflk nicht in der gleichen Koordinate –

Antwort

0

testen

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     android:layout_gravity="center_vertical" 
     android:layout_weight="1" 
     android:paddingLeft="20dp" 
     android:scaleType="fitStart" 
     app:srcCompat="@drawable/food_icon" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_toRightOf="@+id/imageView" 
     android:layout_weight="3" 
     android:orientation="vertical" 
     android:paddingLeft="0dp"> 

     <TextView 
      android:id="@+id/menu" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:gravity="left" 
      android:paddingLeft="0dp" 
      android:text="TextView" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="8dp" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/cost" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView" 
       android:textSize="14sp" /> 

      <TextView 
       android:id="@+id/owner" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView" /> 
     </LinearLayout> 
    </LinearLayout> 

</RelativeLayout> 
+0

@haresshJ Danke, es hat funktioniert. Ich kann wenig ändern, aber das ist was ich will. –

+0

@ Allen.G herzlich willkommen –

0

Ich denke, Sie müssen Android: Weight_sum der übergeordneten Ansicht auf die Summe der Gewichte der untergeordneten Ansichten festlegen. Zum Beispiel würde die erste lineare Layout eine weight_sum von 3 + 1 = 4.

+0

Sie haben meine Frage nicht verstanden. Sie sehen den Namen neben dem Bild. Zum Beispiel sind Joe und Stevekjnl nicht in der gleichen Ausrichtung. –

+0

Vielleicht ist die Textansicht zentriert, also müssen Sie die Textausrichtung nach links setzen? –

+0

schreibe ich android: layout_gravity = "left" für diesen Zweck. Es hat nicht funktioniert. –

Verwandte Themen