Android 高级控件

简介: 高级控件: GridView ScrollView ViewPager SlideMenu PullToRefreshListView 1.ScrollView视图(滚动视图)可以有效的安排这些组件,浏览时可以进行滚屏的操作 垂直滚动——ScrollView 水平滚动——HorizontalScrollView ScrollView是单一容器,只能包含一个组件 练习

高级控件:

GridView

ScrollView
ViewPager
SlideMenu

PullToRefreshListView


1.ScrollView视图(滚动视图)可以有效的安排这些组件,浏览时可以进行滚屏的操作
垂直滚动——ScrollView
水平滚动——HorizontalScrollView
ScrollView是单一容器,只能包含一个组件

练习:设置界面的垂直滚动

                       理想效果                                                         完成效果


布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="30sp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="设置"
                    android:textSize="30sp"
                    android:layout_marginLeft="100dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="意见反馈"
                    android:layout_gravity="center"
                    android:layout_marginLeft="100dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="列表显示摘要"
                    android:textSize="20sp"
                    />
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="170dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="字体大小"
                    android:textSize="20sp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=""
                    android:layout_marginLeft="220dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=">"
                    android:textSize="20sp"
                    android:layout_marginLeft="10dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="列表页评论"
                    android:textSize="20sp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="不限"
                    android:layout_marginLeft="190dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=">"
                    android:textSize="20sp"
                    android:layout_marginLeft="10dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2G/3G网络流量"
                    android:textSize="20sp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="较省流量(智能下图)"
                    android:layout_gravity="center"
                    android:layout_marginLeft="50dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=">"
                    android:textSize="20sp"
                    android:layout_marginLeft="1dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="清理缓存"
                    android:textSize="20sp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="当前缓存:2.48MB"
                    android:layout_gravity="center"
                    android:layout_marginLeft="120dp"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=">"
                    android:textSize="20sp"
                    android:layout_marginLeft="10dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="30dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="推送通知"
                    android:textSize="20sp"
                    />
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:layout_marginLeft="210dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="互动插件"
                    android:textSize="20sp"
                    />
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:layout_marginLeft="210dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="自动优化阅读"
                    android:textSize="20sp"
                    />
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:layout_marginLeft="170dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="收藏时转发"
                    android:textSize="20sp"
                    />
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="190dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="顶踩时转发"
                    android:textSize="20sp"
                    />
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="190dp"
                    />
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#d9d3d3"
                />
        </LinearLayout>
    </ScrollView>
</RelativeLayout>
2.GridView常用属性

android:numColumns=”auto_fit” //GridView的列数设置为自动
android:columnWidth=”90dp " //每列的宽度,也就是Item的宽度
android:stretchMode=”columnWidth“//设置缩放模式,与列宽大小同步
android:verticalSpacing=”10dp” //两行之间的边距
android:horizontalSpacing=”10dp” //两列之间的边距
android:cacheColorHint="#00000000" //去除拖动时默认的黑色背景
android:listSelector="#00000000" //去除选中时的黄色底色
android:scrollbars="none" //隐藏GridView的滚动条

练习:利用GridView完成如下图所示效果

                           理想效果                                                                      完成效果


布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.example.administrator.jreduch05.GridView_Activity">

    <GridView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/gv"
        android:numColumns="auto_fit"
        android:columnWidth="100dp"
        android:horizontalSpacing="5dp"
        android:verticalSpacing="5dp"
        android:cacheColorHint="#00000000"
        android:listSelector="#00000000"
        android:scrollbars="none"
        android:stretchMode="columnWidth"
        >
    </GridView>
</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
<ImageView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:id="@+id/iv"
    android:src="@mipmap/ic_launcher"
    android:scaleType="centerCrop"
    />
    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/tv"
        android:gravity="center"
        android:text="测试"
        />
</LinearLayout>

代码:

package com.example.administrator.jreduch05;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GridView_Activity extends AppCompatActivity {
    private GridView gv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid_view_);
        gv=(GridView) findViewById(R.id.gv);
        final List list =new ArrayList();

        Map map=new HashMap();
        map.put("img", R.mipmap.dahai);
        map.put("name", "深海");
        list.add(map);

         map=new HashMap();
        map.put("img",R.mipmap.jietu1);
        map.put("name","深海");
        list.add(map);

         map=new HashMap();
        map.put("img",R.mipmap.dianzan);
        map.put("name","深海");
        list.add(map);

         map=new HashMap();
        map.put("img",R.mipmap.pinglun);
        map.put("name","深海");
        list.add(map);

         map=new HashMap();
        map.put("img",R.mipmap.renrou);
        map.put("name","深海");
        list.add(map);

         map=new HashMap();
        map.put("img",R.mipmap.sannv);
        map.put("name","深海");
        list.add(map);

        map=new HashMap();
        map.put("img",R.mipmap.wuzhi);
        map.put("name","深海");
        list.add(map);

        /*
        1.simpleAdapter 使用的数据源必须继承 Map 接口
        2.from 参数的意思是 指向数据源 Map中的键
        3.to   参数的意思是  为布局中控件ID赋值
         */

        SimpleAdapter sa=new SimpleAdapter(this,list,
                R.layout.gridlayout,
                new String[]{"img","name"},
                new int[]{R.id.iv,R.id.tv}
                );
        gv.setAdapter(sa);
        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Map map=(Map)list.get(position);
                Intent intent=new Intent(GridView_Activity.this,Datu_Activity.class);
                intent.putExtra("img", (int) map.get("img"));
                startActivity(intent);

            }
        });
    }
}

目录
相关文章
|
数据采集 存储 分布式计算
一篇文章搞懂数据仓库:数据治理(目的、方法、流程)
一篇文章搞懂数据仓库:数据治理(目的、方法、流程)
24935 2
一篇文章搞懂数据仓库:数据治理(目的、方法、流程)
|
10月前
|
人工智能 自然语言处理 文字识别
秒懂全文:盘点13个各具特色的AI智能阅读助手工具
在当今信息爆炸的时代,AI阅读工具正在革新我们的阅读方式,成为了提高效率、优化阅读体验的关键。这类AI阅读辅助工具,只需要上传文件或者输入链接,便可以直接以聊天对话的形式进行一键总结和智能问答,满足用户AI PDF 阅读、AI文档问答分析、AI音视频总结等多种实用需求,高效提炼信息要点精华,建立属于自己的AI知识管理和信息管理工作流。对此,根据阅读场景,精选了 13 个具有代表性、各具特点的高质量 AI 阅读助手助理。 具体如何选择,见文末总结。
1047 1
秒懂全文:盘点13个各具特色的AI智能阅读助手工具
|
9月前
|
机器学习/深度学习 人工智能 算法
探究人工智能在现代医疗诊断中的应用与挑战
本文旨在深入探讨人工智能技术在现代医疗诊断领域中的应用及其所面临的挑战。随着科技的飞速发展,人工智能已逐渐渗透到医疗行业的多个方面,特别是在医疗诊断领域,AI的应用不仅提高了诊断的准确性和效率,还极大地减轻了医生的工作负担。然而,尽管人工智能在医疗诊断中展现出巨大的潜力,其发展过程中也遇到了一系列挑战,如数据隐私保护、算法的透明度和公平性等问题。本文通过对现有文献的综合分析,阐述了人工智能在医疗诊断中的具体应用案例,分析了这些技术的优势与不足,并对其未来的发展趋势进行了预测和建议。
131 5
|
开发者 Python
Python 操作 Excel 全攻略 | 包括读取、写入、表格操作、图像输出和字体设置
Python 操作 Excel 全攻略 | 包括读取、写入、表格操作、图像输出和字体设置
1712 0
|
9月前
|
存储 安全 网络安全
智能家居安全:从入门到精通
在这篇文章中,我们将深入探讨智能家居系统的安全性问题。随着科技的发展,智能家居设备越来越普及,但随之而来的是安全问题的增多。本文将带你了解智能家居系统可能面临的安全风险,并提供实用的防护措施,帮助你构建一个安全的智能家庭环境。
|
Go
【go】两数求和
【go】两数求和
36 0
|
Java 网络架构 Spring
详解 SpringMVC 的 @RequestMapping 注解
详解 SpringMVC 的 @RequestMapping 注解
|
机器学习/深度学习 人工智能 自然语言处理
2022科大讯飞AI开发者大赛,来了!
6月9日,第四届(2018~2022)科大讯飞AI开发者大赛,正式启动! 科大讯飞联合优质企业、知名高校、融投资机构等53家合作伙伴, 围绕十大新兴产业开启算法、应用、编程赛、虚拟形象选拔、辩论赛、创意集市创意赛等108个赛道方向,覆盖了智能语音、视觉、自然语言、图文识别等人工智能热门技术,涵盖了元宇宙、农业养殖、遗址文化、生物与环保、医疗健康、地理遥感、企业数字化、智能家居、电商销售等多领域。
|
关系型数据库 MySQL
MySQL的Relay Log日志是干什么的?底层原理是什么?
MySQL的Relay Log日志是干什么的?底层原理是什么?
928 0
|
SQL 存储 分布式计算