Square Grid - XML [英] Square Grid - XML

查看:170
本文介绍了Square Grid - XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的学习中,我必须做一个Android应用程序,从气象站中检索天气数据。这些将以块形式显示。
这些街区将在4列和2列出发。



所以我想创建一个4列和2行的方形网格来提供这些块。



有人会有一个解决方案来帮助我创建这个网格吗?

解决方案

有许多选项:
1.您可以选择回收站视图GridLayoutManager

 < android.support.v7.widget.RecyclerView 
android:id =@ + id / main_grid
android:layout_width =match_parent
android:layout_height =match_parent
android:padding =2dp
/>

所以在内部活动中,您会做类似于

  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:horizo​​ntalSpacing =2dp
android:numColumns =4
android:padding =4dp
android:stretchMode =columnWidth/> ;

对于固定商品尺寸,您应该使用

 < 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 =horizo​​ntal
>

< 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!
/>

请确保您在应用程序中添加了这个gradle

  compile'c​​om.android.support:gridlayout-v7:23.0.1'


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.

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?

解决方案

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. You choose grid view

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

Make sure you add this in your app gradle

compile 'com.android.support:gridlayout-v7:23.0.1'

这篇关于Square Grid - XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆