2016-04-22 6 views
0

Derzeit mein Listview-Design sieht aus wie enter image description hereWie andorid Layout wie pro Bild unter

Aber ich will es aussehen enter image description here

Bild unten gegeben ändern Wo Bild auf der rechten Seite sein wird, den Titel in Fettdruck und Untertitel direkt darunter. Welche Änderungen muss ich in meinem Layout vornehmen? Unten ist mein Code. Danke in Voraus.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="4dp" 
    android:orientation="vertical" > 

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

     <ImageView 
      android:id="@+id/ivImage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="8dp" 
      android:src="@drawable/ic_launcher"/> 

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

      <TextView 
       android:id="@+id/tvName" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Tom Cruise" 
       android:textColor="#166CED" 
       android:textAppearance="?android:attr/textAppearanceLarge" /> 



     </LinearLayout> 

    </LinearLayout> 

    <TextView 
     android:id="@+id/tvDescriptionn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#009A57" 
     android:text="Description" /> 



</LinearLayout> 
+0

Das Ändern der Position der Bildansichten und das Einfügen der Ränder wird den Zweck erfüllen. –

+0

Meiner Meinung nach besser 'GridLayout' für bessere Leistung :). P.S. Beginnen Sie zu denken, suchen Sie nicht jemanden, der es für Sie tun wird. –

+0

wird das Bild unter der Überschrift sein? oder oben rechts? –

Antwort

1

Für ein besseres Ergebnis, um Ihre Ansicht zu verwalten, verwenden Sie relaylayout. Sie können Ihr Layout als Beispiel verwalten geben unten- Screenshot

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:id="@+id/LinearLayout1" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:padding="4dp" 
android:orientation="vertical"> 
<android.support.v7.widget.CardView 
    android:id="@+id/cardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="5dp" 
    android:layout_marginTop="5dp" 
    card_view:cardBackgroundColor="@color/grey"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/arrow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="5dp" 
      android:src="@drawable/arrow"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/arrow" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/tvName" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Murdochs needed counselling after hacking scandle says magazine" 
      android:textColor="#166CED" 
      android:padding="5dp" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 


     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <TextView 
       android:id="@+id/tvSubtitle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_toLeftOf="@+id/ivImage" 
       android:padding="5dp" 
       android:text="NEW YORK:The British phone hacking scandle" 
       android:textColor="#000" 
       android:textAppearance="?android:attr/textAppearanceSmall" /> 
      <ImageView 
       android:id="@+id/ivImage" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="8dp" 
       android:layout_centerVertical="true" 
       android:layout_alignParentRight="true" 
       android:src="@drawable/ic_launcher"/> 
     </RelativeLayout> 

    </LinearLayout> 
    </RelativeLayout> 
    </android.support.v7.widget.CardView> 
    </LinearLayout> 
+0

Danke, aber was ist, wenn ich nicht Widget-Karte verwenden möchte? – user45678

+0

Es ist sehr einfach ersetzen Sie es einfach @ user45678 –

+0

Danke, ich habe es getan – user45678

-1

Innerhalb LinearLayout, legen Sie Textansicht an der Spitze, um den Titel anzuzeigen. Stellen Sie height wrap_content und width match_parent her.

Darunter fügen Sie linearlayout hinzu, das textview und Bild enthält. Stellen Sie die Ausrichtung horizontal auf das Innenliner-Layout ein.

Für eine bessere Platzierung können Sie immer relative Layout verwenden. zum Beispiel

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.testlayout.MainActivity" > 

<TextView 

    android:id="@+id/titleText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 

<TextView 
    android:id="@+id/descriptionText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/titleText" 
    android:text="description"/> 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/titleText" 
    android:layout_toLeftOf="@+id/rightArrow" 
    android:src="@drawable/ic_launcher" /> 

<ImageView 
    android:id="@+id/rightArrow" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/titleText" 
    android:src="@drawable/ic_launcher" 
    android:layout_alignParentEnd="true" /> 



</RelativeLayout> 
1

Ich würde vorschlagen, Sie relatives Layout zu verwenden. Dadurch wird Ihr Layout flexibler zum Bearbeiten. Ich habe unten ein Layout vorgeschlagen, probieren Sie es aus.

<?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="match_parent"> 

<TextView 
    android:id="@+id/tvName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="10dp" 
    android:gravity="center_horizontal" 
    android:text="Tom Cruse" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:textColor="#166CED" /> 

<ImageView 
    android:id="@+id/ivImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_below="@+id/tvName" 
    android:layout_margin="5dp" 
    android:src="@drawable/ic_launcher" /> 

<TextView 
    android:id="@+id/tvDescriptionn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentStart="true" 
    android:layout_below="@+id/tvName" 
    android:layout_margin="10dp" 
    android:layout_toLeftOf="@+id/ivImage" 
    android:text="Description" 
    android:textColor="#009A57" /> 
</RelativeLayout> 

Bitte akzeptieren Sie diese Antwort, wenn es für Sie arbeitete.