2017-08-20 5 views
-4

Das folgende Layout wird in eine Listenansicht auf einem separaten Tab eingefügt, aber ich habe Probleme mit dieser Ansicht für meinen benutzerdefinierten Adapter.Ich kann das Android-Layout, das ich will, nicht bekommen

Die erste imageView ID 'Symbol' möchte ich auf der linken Seite. Die TextView-ID 'item' möchte ich in der Mitte rechts von id icon und die textView 'textView1' möchte ich unter dem Element, das ist in Ordnung, denn das ist in Ordnung, auch der Text rechts neben dem Symbol ist in Ordnung.

Das Problem, das ich habe, ist mit der ID-Pause und ID-Symbol2. Ich möchte diese ganz rechts von den Textansichten und Bildansichten oben sehen.

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

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:padding="5dp" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:weightSum="1"> 

     <TextView 
      android:id="@+id/item" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="5dp" 
      android:padding="2dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#4CBE99" 
      android:textAllCaps="true" 
      android:textStyle="bold" 
      /> 
     <ImageView 
      android:id="@+id/pause" 
      android:layout_gravity="left" 
      android:layout_width="35dp" 
      android:layout_height="35dp" 
      android:padding="5dp" 
      android:orientation="horizontal" 
      /> 
     <ImageView 
      android:id="@+id/icon2" 
      android:layout_gravity="right" 
      android:layout_width="35dp" 
      android:layout_height="35dp" 
      android:padding="5dp" 
      android:orientation="horizontal" 
      android:layout_toRightOf="@id/pause" 
      /> 
     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" /> 

     <com.google.android.gms.ads.NativeExpressAdView 
      android:id="@+id/adView" 
      android:layout_width="420dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:visibility="visible" 
      ads:adUnitId="ca-app-pub-3940256099942544/2793859312" 
      ads:adSize="200x80" 
      android:layout_weight="3.40"></com.google.android.gms.ads.NativeExpressAdView> 
    </LinearLayout> 

</LinearLayout> 

Edit:

enter image description here

+0

Es ist besser, zeigen Sie Bild oder Screenshot von dem, was Sie erreichen möchten. Es wird helfen – Inducesmile

+0

@Inducesmile ist das oben in Ordnung? – Sam

+0

Also ist dies ein Layout für Zeilen in einer Liste? – Mehmed

Antwort

0

Dies ist für jedes Listenelement

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

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="4" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:src="@drawable/add" 
     android:padding="5dp" /> 

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

     <TextView 
      android:id="@+id/item" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="5dp" 
      android:padding="2dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#4CBE99" 
      android:text="Item" 
      android:textAllCaps="true" 
      android:textStyle="bold" /> 


     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView1" 
      android:layout_marginLeft="10dp" /> 


    </LinearLayout> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/pause" 
     android:layout_gravity="center_vertical" 
     android:layout_width="35dp" 
     android:layout_height="35dp" 
     android:padding="5dp" 
     android:src="@drawable/add" 
     android:orientation="horizontal" 
     /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/icon2" 
     android:layout_width="35dp" 
     android:layout_height="35dp" 
     android:padding="5dp" 
     android:layout_gravity="center_vertical" 
     android:src="@drawable/add" 
     android:orientation="horizontal" /> 

</LinearLayout> 

enter image description here

I t Verbergen Sie die NativeExpressAdView wird im selben Layout mit Ihrer Listview.

1

dies erreicht werden kann ConstraintLayout ohne Verschachtelung Layouts:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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="wrap_content"> 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="60dp" 
     android:layout_height="60dp" 
     android:padding="5dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <TextView 
     android:id="@+id/item" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginStart="10dp" 
     android:layout_marginTop="5dp" 
     android:padding="2dp" 
     android:textAllCaps="true" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#4CBE99" 
     android:textStyle="bold" 
     app:layout_constraintLeft_toRightOf="@+id/icon" 
     app:layout_constraintRight_toLeftOf="@+id/pause" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginStart="10dp" 
     app:layout_constraintLeft_toRightOf="@+id/icon" 
     app:layout_constraintRight_toLeftOf="@+id/pause" 
     app:layout_constraintTop_toBottomOf="@+id/item" /> 

    <ImageView 
     android:id="@+id/pause" 
     android:layout_width="35dp" 
     android:layout_height="35dp" 
     android:padding="5dp" 
     app:layout_constraintRight_toLeftOf="@+id/icon2" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <ImageView 
     android:id="@+id/icon2" 
     android:layout_width="35dp" 
     android:layout_height="35dp" 
     android:padding="5dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

</android.support.constraint.ConstraintLayout> 

Vergessen Sie nicht, die folgende Zeile in den Abhängigkeiten in build.gradle hinzuzufügen:

compile 'com.android.support.constraint:constraint-layout:1.0.2' 
+0

Hallo, ich habe es versucht und die Abhängigkeit hinzugefügt, aber es zeigt Fehler wie Fehler: (31, 46) Keine Ressource gefunden, die den angegebenen Namen (bei 'layout_constraintRight_toLeftOf' mit Wert '@ id/Pause') entspricht. – Sam

+0

Ja, das ist ein Fehler, ich habe das XML aktualisiert, können Sie es erneut versuchen? – Mehmed

Verwandte Themen