Android网格布局的简单使用
16lz
2022-07-06
Android网格布局的简单使用
运行效果如图:
点击事件效果:
功能:GridView 组件的使用,图片以3*8排列,点击图片弹出对话框显示图片。
- Java反射
- SimpleAdapter的进行封装数据
- OnItemClickListener事件的使用
- AlertDialog的基本使用
主布局文件 activity_main.xml
"http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.gridviewdemo.MainActivity" > "@+id/gv" android:layout_width="match_parent" android:layout_height="wrap_content" android:numColumns="3" /></RelativeLayout>
显示Item的布局模板 title_view.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/img" android:layout_width="match_parent" android:layout_height="wrap_content" android:contentDescription="@string/bookdesc" android:scaleType="center" />LinearLayout>
主程序 MainActivity.java
package com.example.gridviewdemo;import android.app.Activity;import android.app.AlertDialog;import android.app.Dialog;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.os.Bundle;import android.view.View;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.GridView;import android.widget.ImageView;import android.widget.SimpleAdapter;import java.lang.reflect.Field;import java.util.*;public class MainActivity extends Activity { private GridView gridView = null; private List
2015年9月28日
一步一个脚印
更多相关文章
- 箭头函数的基础使用
- NPM 和webpack 的基础使用
- Python list sort方法的具体使用
- 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
- android 使用html5作布局文件: webview跟javascript交互
- Android(安卓)matrix 控制图片的旋转、缩放、移动
- Android(安卓)Resource介绍和使用
- "Failed to fetch URL https://dl-ssl.google.com/android/repos
- 使用NetBeans搭建Android开发环境