-3

Ich mag das Layout so machen:Welches Layout sollte ich für ein Tabellenlayout in Android verwenden?

enter image description here

Kann mich jemand führen, welches Layout besser geeignet ist (ich habe feste Anzahl von Zeilen und Spalten)?.

Relatives Layout oder lineares Layout? oder etwas anderes?

+0

können Sie verwenden Tablelayout, Gridlayout oder RecyclerView mit Gridlayout-Manager Es ist auf Ihrer Anforderung hängt –

+0

wenn Sie Zeilen und Spalte festgelegt haben, dann Verwenden Sie ein lineares Layout. Wenn die Anzahl der Zeilen/Spalten vom Serverergebnis abweicht, verwenden Sie das Tabellenlayout –

+0

. Ja, ich habe feste Zeilen und Spalten –

Antwort

2

Verwenden Sie den folgenden Code für das Design wollen Sie

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

    <RelativeLayout 
     android:background="#8FDFBF" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:layout_marginEnd="1dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/card_title1" 
      android:text="title1" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_below="@+id/card_title1" 
      android:layout_marginTop="20dp" 
      android:text="12" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_weight="1" 
     android:background="#8FDFBF" 
     android:gravity="center" 
     android:layout_marginStart="1dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/card_title2" 
      android:text="title2" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_below="@+id/card_title2" 
      android:layout_marginTop="20dp" 
      android:text="21" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

</LinearLayout> 

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_marginTop="@dimen/margin_2" 
    android:layout_width="match_parent" 
    android:layout_height="100dp"> 

    <RelativeLayout 
     android:background="#4ADCA1" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:layout_marginEnd="1dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/card_title3" 
      android:text="title3" 
      android:gravity="center" 
      android:textColor="@android:color/white" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_below="@+id/card_title3" 
      android:layout_marginTop="20dp" 
      android:text="25 c" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_weight="1" 
     android:background="#4ADCA1" 
     android:gravity="center" 
     android:layout_marginStart="1dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/card_title4" 
      android:text="title4" 
      android:gravity="center" 
      android:textColor="@android:color/white" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_below="@+id/card_title4" 
      android:layout_marginTop="20dp" 
      android:text="40 mb" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

</LinearLayout> 

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_marginTop="@dimen/margin_2" 
    android:layout_width="match_parent" 
    android:layout_height="100dp"> 

    <RelativeLayout 
     android:background="#9EFAD5" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:layout_marginEnd="1dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/card_title5" 
      android:text="title5" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_below="@+id/card_title5" 
      android:layout_marginTop="20dp" 
      android:text="50 %" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_weight="1" 
     android:background="#9EFAD5" 
     android:gravity="center" 
     android:layout_marginStart="1dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TextView 
      android:id="@+id/card_title6" 
      android:text="title6" 
      android:gravity="center" 
      android:textColor="@android:color/white" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:layout_below="@+id/card_title6" 
      android:layout_marginTop="20dp" 
      android:text="90 %" 
      android:textColor="@android:color/white" 
      android:gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

</LinearLayout> 

+0

wow. das war schnell. vielen Dank Alter . –

+0

glücklich zu helfen ... –

Verwandte Themen