使用场景:淘宝、京东等软件上,主界面上的布局通常是两列,每一个条目都是由图片和描述以及价格构成,这样的布局可以使用GridView轻松实现。
1.布局文件中使用GridView控件
<?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">
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="4"/>
</LinearLayout>
设计图效果