2016-03-26 9 views
1

Ich mag Karte erstellen, wie -Marge und das Layout in android

pictures,

Ich versuche margin zu verwenden, aber nicht mit dieser Idee zu gewinnen. Ich versuche für alle Element persönliche Ansicht erstellen und padding oder margin verwenden, aber ich habe kein Ergebnis.

Ich habe Code wie die

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/tools" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <RelativeLayout 
     android:id="@+id/rlCardBlock" 
     style="@style/Widget.CardContent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 


     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="24dp" 
      android:maxLines="2" 
      android:textStyle="bold" 
      android:text="title"/> 

     <TextView 
      android:id="@+id/content" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/title" 
      android:maxLines="5" 
      android:text="content" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@id/content" 
      android:layout_marginBottom="8dp" 
      android:background="@null" 
      android:src="@drawable/ic_more_vert_black_36dp" /> 
    </RelativeLayout> 
</android.support.v7.widget.CardView> 

Danke für Ihre Aufmerksamkeit.

+0

Was ist das Problem? –

+0

Ich weiß nicht, wie Raum erstellen wie in Bild –

Antwort

1

Android verfügt bereits über vordefinierte Widgets für Karten- und Recycleransicht. Sie können die Android Cardview und Recycler-Ansicht für Ihr Problem verwenden, es ist einfach für Sie zu implementieren.

Für diesen Sie zunächst Abhängigkeiten hinzufügen, wenn Sie als IDE Android Studio verwenden

compile 'com.android.support:cardview-v7:21.0.+' 
compile 'com.android.support:recyclerview-v7:21.0.+' 

dann in Ihrer obigen Änderung metioned Code es in

<?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" 
    android:padding="16dp" 
    > 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/cv" 
     > 



<LinearLayout 
android:id="@+id/rlCardBlock" 
style="@style/Widget.CardContent" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 


<TextView 
    android:id="@+id/title" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="24dp" 
    android:maxLines="2" 
    android:textStyle="bold" 
    android:text="title"/> 

<TextView 
    android:id="@+id/content" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/title" 
    android:layout_marginTop="12dp" 
    android:maxLines="5" 
    android:text="content" /> 

<TextView 
    android:id="@+id/content" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/description" 
    android:layout_marginTop="16dp" 
    android:maxLines="5" 
    android:text="content" /> 

<LinearLayout 
android:id="@+id/rlCardBlock" 
style="@style/Widget.CardContent" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="16dp" 
android:orientation="horizontal"> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Action 1" 
    android:id="@+id/button1" 
    /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Action 2" 
    android:id="@+id/button2" 
    /> 

</LinearLayout> 

</LinearLayout> 

    </android.support.v7.widget.CardView> 

</LinearLayout> 

hier ist das Tutorial: link

+0

Ich benutze Cardview und Recycler anzeigen, Frage - wie kann ich Raum beetween Element in meiner Karte, wie in meinem Bild –

+0

Platz bedeutet Polsterung? – nifCody

+0

@sharpsolutions Benötigen Sie das absolute Layout, das Sie im Bild zeigen. Bin ich richtig – nifCody

0

Auf Titel verwenden android:layout_marginTop="22dp" Auf Untertitel Auf Text android:layout_margin="16dp"

verwenden, aber kann man andere Wege wählen, entweder Polsterung oder Marge

Verwandte Themen