我怎样才能创建这样的

我怎样才能创建这样的

本文介绍了我怎样才能创建这样的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能像这样创建?

How can I create like this?

我无法创建这个.

推荐答案

你可以通过把它放在你的 MainActivity.java 中来实现这一点(我做了一些 Strings 作为数据为了节省时间):

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);

    }
}

现在您在 activity_main.xml 布局中定义 GridView:

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>

不要忘记将其放入 dependencies 下的 build.gradle(:app) 文件夹:

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:

干杯,用你的 ImageViewCardViewImageButton 代替我的 Strings.快乐编码:)

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

这篇关于我怎样才能创建这样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 05:19