Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Android Grid in xml erstellen

04.01.2021 (👁99)

Android Grid in xml erstellen

 

In Android kann man ein Grid erstellen, indem man ein GridLayout als Element einbettet.

 

<GridLayout
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:columnCount="3"
       
android:rowCount="7"
       
android:background="@color/teal_200"

       
>
        <
Space
           
android:layout_column="0"
           
android:layout_row="0"
           
android:layout_margin="11dp"
           
/>
        <
Space
           
android:layout_column="1"
           
android:layout_row="0"
           
android:layout_margin="11dp"
           
/>

 

Mit RowCount und ColumnCount kann man die vordefiniert Anzahl an Spalten und Zeilen festlegen

        android:columnCount="3"
       
android:rowCount="7"

 

Den Abstand zwischen den Zeilen und Spalten kann man durch Space-Elemente erzielen

<Space
           
android:layout_column="0"
           
android:layout_row="0"
           
android:layout_margin="11dp"
           
/>
        <
Space
           
android:layout_column="1"
           
android:layout_row="0"
           
android:layout_margin="11dp"
           
/>

 

 

 

 

<?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"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
tools:context=".MainActivity"
   
>

    <
GridLayout
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:columnCount="3"
       
android:rowCount="7"
       
android:background="@color/teal_200"

       
>
        <
Space
           
android:layout_column="0"
           
android:layout_row="0"
           
android:layout_margin="11dp"
           
/>
        <
Space
           
android:layout_column="1"
           
android:layout_row="0"
           
android:layout_margin="11dp"
           
/>
        <
Space
           
android:layout_column="2"
           
android:layout_row="0"
           
android:layout_margin="11dp"
           
/>

        <
Space
           
android:layout_column="0"
           
android:layout_row="1"
           
android:layout_margin="11dp"
           
/>
        <
Space
           
android:layout_column="0"
           
android:layout_row="1"
           
android:layout_margin="11dp"
           
/>

       
        <
TextView android:text="A1"
           
android:layout_column="0"
           
android:layout_row="0"
           
/>
        <
TextView android:text="B1"
           
android:layout_column="1"
           
android:layout_row="0"
           
/>
        <
TextView android:text="C1"
           
android:layout_column="2"
           
android:layout_row="0"
           
/>

        <
TextView android:text="A2"
           
android:layout_column="0"
           
android:layout_row="1"
           
/>
        <
TextView android:text="B2"
           
android:layout_column="1"
           
android:layout_row="1"
           
/>
        <
TextView android:text="C2"
           
android:layout_column="2"
           
android:layout_row="1"
           
/>

    </
GridLayout>

</
LinearLayout>