0

How can I create like this?

screenshot

I can't create this.

hata
  • 11,633
  • 6
  • 46
  • 69
Sanjoy
  • 11
  • 1
  • try this https://stackoverflow.com/a/40587169/7626390 – pankaj sharma Apr 18 '21 at 17:47
  • Welcome to Stack Overflow! Very rarely do people just simply write code for you. We'd like to see you put some effort into your code and display it in the question. Check out [here](https://stackoverflow.com/help/how-to-ask) if you want to see how. – PerplexingParadox Apr 18 '21 at 19:39

2 Answers2

1

You can achieve that with putting that in your MainActivity.java (I made some Strings as data for saving time):

package com.example.myapplication;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import androidx.appcompat.app.AppCompatActivity;


public class MainActivity extends AppCompatActivity {
GridView gridView;
String [] yourData = {"Data1","Data2", "Data3", "Data4", "Data 5", "Data6","Data7", "Data8", "Data9", "Data10", "Data11", "Data12"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView = findViewById(R.id.GridView);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item, yourData);
        gridView.setAdapter(adapter);

    }
}

Now you define the GridView in your activity_main.xml layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".MainActivity"
    android:orientation="horizontal">


    <GridView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="3"
        android:id="@+id/GridView"/>

</LinearLayout>

Don't forget to put that into your build.gradle(:app) folder under dependencies:

dependencies {

    implementation 'androidx.gridlayout:gridlayout:1.0.0'

That's the result you will get:

The result

Cheers and try that with your ImageView, CardView or ImageButton instead of my Strings. Happy Coding :)

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33
0

Use GridLayout (Except for the top row, which is called Toolbar or ActionBar).

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33
hata
  • 11,633
  • 6
  • 46
  • 69