Square Grid - XML(方格 - XML)
问题描述
在我的学习中,我必须做一个从气象站检索天气数据的 Android 应用程序.这些将显示在块中.这些块将分开 4 列和 2 行.
In my studies, I have to do an Android application that retrieves weather data from a weather station. These will be displayed in blocks. These blocks will depart on 4 columns and 2 rows.
所以我想创建一个 4 列 2 线的方形网格来提供块.
So I wanted to create a square grid of 4 columns and 2 lines for the provision of the blocks.
有人可以帮我创建这个网格吗?
Someone would have a solution to help me create this grid, please?
推荐答案
有很多选择:1.可以用GridLayoutManager选择recycler view
There are many options : 1. you can choose a recycler view with GridLayoutManager
<android.support.v7.widget.RecyclerView
android:id="@+id/main_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
/>
所以在活动内部你会做类似的事情
So inside activity you will do something like
mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), COLUMN_COUNT));
2.你选择网格视图
<GridView
android:id="@+id/grid"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"
android:horizontalSpacing="2dp"
android:numColumns="4"
android:padding="4dp"
android:stretchMode="columnWidth"/>
对于固定的项目大小,您应该使用
For fixed item size you should use
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:columnCount="4"
app:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
</android.support.v7.widget.GridLayout>
确保将其添加到您的应用 gradle 中
Make sure you add this in your app gradle
compile 'com.android.support:gridlayout-v7:23.0.1'
这篇关于方格 - XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:方格 - XML
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
