当前位置: 首页 > news >正文

Android组件通信——ActivityGroup(二十五)

1. ActivityGroup

1.1 知识点

(1)了解ActivityGroup的作用;

(2)使用ActivityGroup进行复杂标签菜单的实现;

(3)使用PopupWindow组件实现弹出菜单组件开发;

1.2 具体内容

<LinearLayout 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"android:orientation="vertical"tools:context=".ActivityGroupActivity" ><LinearLayout android:gravity="center_horizontal"android:layout_width="match_parent"android:layout_height="wrap_content"><TextView android:id="@+id/cust_title"android:textSize="28sp"android:text="ActivityGroup实现分页导航"android:layout_width="wrap_content"android:layout_height="wrap_content"/> </LinearLayout><!-- 中间动态加载的View --><ScrollView android:measureAllChildren="true"android:id="@+id/containerBody" android:layout_weight="1"android:layout_height="fill_parent"android:layout_width="fill_parent"></ScrollView><LinearLayout android:background="@android:color/black"android:layout_gravity="bottom"android:orientation="horizontal"android:layout_height="wrap_content"android:layout_width="fill_parent"><!-- 导航按钮1 --><ImageView android:id="@+id/img1"android:src="@android:drawable/ic_dialog_dialer"android:layout_marginLeft="7dp" android:layout_marginTop="3dp"android:layout_marginBottom="3dp"android:layout_height="wrap_content"android:layout_width="wrap_content"/><!-- 导航按钮2 --><ImageView android:id="@+id/img2"android:src="@android:drawable/ic_dialog_info"android:layout_marginLeft="7dp" android:layout_marginTop="3dp"android:layout_marginBottom="3dp"android:layout_height="wrap_content"android:layout_width="wrap_content"/><!-- 导航按钮3 --><ImageView android:id="@+id/img3"android:src="@android:drawable/ic_dialog_alert"android:layout_marginLeft="7dp" android:layout_marginTop="3dp"android:layout_marginBottom="3dp"android:layout_height="wrap_content"android:layout_width="wrap_content"/></LinearLayout></LinearLayout>
package com.example.activitygroupproject;import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ScrollView;public class ActivityGroupActivity extends ActivityGroup {ScrollView container =null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏setContentView(R.layout.activity_activity_group);container = (ScrollView) super.findViewById(R.id.containerBody);//导航1ImageView img1= (ImageView) super.findViewById(R.id.img1);img1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {container.removeAllViews();//清空子Viewcontainer.addView(getLocalActivityManager().startActivity("Module1", new Intent(ActivityGroupActivity.this,ModuleView1.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());}});//导航2ImageView img2= (ImageView) super.findViewById(R.id.img2);img2.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {container.removeAllViews();//清空子Viewcontainer.addView(getLocalActivityManager().startActivity("Module2", new Intent(ActivityGroupActivity.this,ModuleView2.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());}});//导航3ImageView img3= (ImageView) super.findViewById(R.id.img3);img3.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {container.removeAllViews();//清空子Viewcontainer.addView(getLocalActivityManager().startActivity("Module3", new Intent(ActivityGroupActivity.this,ModuleView3.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());}});}}

下面是子Activity的布局和文件:

<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"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=".ModuleView1" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="第一个Module" /></RelativeLayout>
package com.example.activitygroupproject;import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;public class ModuleView1 extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_module_view1);}}

共有三个子Activity,其余两个类似,就只写一个。

以下实现目前非常流行的标签页实现形式FragmentTabHost+ViewPager。

主布局:

<LinearLayout 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"android:orientation="vertical"tools:context=".FragmentTabHostActivity" ><android.support.v4.view.ViewPagerandroid:id="@+id/pager"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"/><FrameLayoutandroid:visibility="gone"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"/><android.support.v4.app.FragmentTabHostandroid:id="@android:id/tabhost"android:layout_width="match_parent"android:layout_height="wrap_content"><FrameLayout android:id="@android:id/tabcontent"android:layout_width="0dp"android:layout_height="0dp"android:layout_weight="0"></FrameLayout></android.support.v4.app.FragmentTabHost></LinearLayout>

Activity:

package com.example.fragmenttabhost;import java.util.ArrayList;
import java.util.List;import android.R.color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTabHost;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.TextView;public class FragmentTabHostActivity extends FragmentActivity {FragmentTabHost mTabHost = null;LayoutInflater layoutInflater = null;Class fragmentArray[] = {FragmentPage1.class,FragmentPage2.class,FragmentPage3.class};int mImageViewArray[] = {android.R.drawable.ic_dialog_dialer,android.R.drawable.ic_dialog_info,android.R.drawable.ic_dialog_alert};String mTextViewArray[] = {"首页","消息","好友"};ViewPager vp;List<Fragment> list = new ArrayList<Fragment>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_fragment_tab_host);//实例化组件initView();initPager();}public void initView(){vp = (ViewPager) super.findViewById(R.id.pager);vp.setOnPageChangeListener(new ViewPagerListener());layoutInflater = LayoutInflater.from(this);//实例化布局对象mTabHost = (FragmentTabHost) super.findViewById(android.R.id.tabhost);mTabHost.setup(this,getSupportFragmentManager(),R.id.pager);//实例化FragmentTabHost对象mTabHost.setOnTabChangedListener(new TabHostListener());int count = fragmentArray.length;//获取子tab的个数for(int i= 0;i<count;i++){//为每一个Tab按钮设置图标文字和内容TabSpec tabSpec = mTabHost.newTabSpec(mTextViewArray[i]).setIndicator(getTabItemView(i));mTabHost.addTab(tabSpec,fragmentArray[i],null);//将子tab添加进TabHost//设置按钮的背景mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(color.background_dark);}}private void initPager(){FragmentPage1 p1 = new FragmentPage1();FragmentPage2 p2 = new FragmentPage2();FragmentPage3 p3 = new FragmentPage3();list.add(p1);list.add(p2);list.add(p3);vp.setAdapter(new MyAdapter(getSupportFragmentManager()));}private View getTabItemView(int index){View view = layoutInflater.inflate(R.layout.tabspec_layout, null);ImageView img = (ImageView) view.findViewById(R.id.img);img.setImageResource(mImageViewArray[index]);TextView tv = (TextView) view.findViewById(R.id.tv);tv.setText(mTextViewArray[index]);return view;}class ViewPagerListener implements OnPageChangeListener{@Overridepublic void onPageScrollStateChanged(int arg0) {// TODO Auto-generated method stub}@Overridepublic void onPageScrolled(int arg0, float arg1, int arg2) {// TODO Auto-generated method stub}@Overridepublic void onPageSelected(int arg0) {//根据焦点来确认切换到那个TabTabWidget  widget = mTabHost.getTabWidget();int oldFocusability = widget.getDescendantFocusability();widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);mTabHost.setCurrentTab(arg0);widget.setDescendantFocusability(oldFocusability);}}class TabHostListener implements OnTabChangeListener{@Overridepublic void onTabChanged(String tabId) {int position = mTabHost.getCurrentTab();vp.setCurrentItem(position);}}class MyAdapter extends FragmentPagerAdapter{public MyAdapter(FragmentManager fm) {super(fm);// TODO Auto-generated constructor stub}@Overridepublic Fragment getItem(int arg0) {// TODO Auto-generated method stubreturn list.get(arg0);}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn list.size();}}
}

单个标签布局:

<?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="wrap_content"android:layout_height="wrap_content"android:padding="3dp"/><TextView android:id="@+id/tv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="10sp"android:textColor="#FFFFFF"/></LinearLayout>

单个fragment:

package com.example.fragmenttabhost;import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;public class FragmentPage1 extends Fragment {@Overridepublic View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){return inflater.inflate(R.layout.fragment, null);}
}

单个fragment布局:

<?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" ><ImageViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:src="@drawable/ic_launcher"/></LinearLayout>

1.3 小结

(1)ActivityGroup可以让多个Activity在一个屏幕上集中显示;

(2)通过PopupWindow组件可以实现弹出菜单的功能。

相关文章:

Android组件通信——ActivityGroup(二十五)

1. ActivityGroup 1.1 知识点 &#xff08;1&#xff09;了解ActivityGroup的作用&#xff1b; &#xff08;2&#xff09;使用ActivityGroup进行复杂标签菜单的实现&#xff1b; &#xff08;3&#xff09;使用PopupWindow组件实现弹出菜单组件开发&#xff1b; 1.2 具体…...

js的继承的方式

1.对象冒充继承 使用 bind,call,apply 解决构造函数属性的继承 缺点:不能继承原型上的属性和方法 //-------------父类-------------function Person(name, age, sex) {this.name name;this.age age;this.sex sex;}Person.prototype.run function () {console.log(我${this…...

聊聊HttpClient的重试机制

序 本文主要研究一下HttpClient的重试机制 HttpRequestRetryHandler org/apache/http/client/HttpRequestRetryHandler.java public interface HttpRequestRetryHandler {/*** Determines if a method should be retried after an IOException* occurs during execution.**…...

北邮22级信通院数电:Verilog-FPGA(4)第三周实验:按键消抖、呼吸灯、流水灯 操作流程注意事项

北邮22信通一枚~ 跟随课程进度更新北邮信通院数字系统设计的笔记、代码和文章 持续关注作者 迎接数电实验学习~ 获取更多文章&#xff0c;请访问专栏&#xff1a; 北邮22级信通院数电实验_青山如墨雨如画的博客-CSDN博客 目录 一.注意事项 二.按键消抖 2.1 LED_deboun…...

Ghidra101再入门(上?)-Ghidra架构介绍

Ghidra101再入门(上&#xff1f;)-Ghidra架构介绍 最近有群友问我&#xff0c;说&#xff1a;“用了很多年的IDA&#xff0c;最近想看看Ghidra&#xff0c;这应该怎么进行入门&#xff1f;“这可难到我了。。 我发现&#xff0c;市面上虽然介绍Ghidra怎么用的文章和书籍很多&…...

Vue3路由引入报错解决:无法找到模块“xxx.vue”的声明文件 xxx隐式拥有 “any“ 类型。

这类情况应该遇见过吧&#xff0c;这是因为 TypeScript只能理解 .ts 文件&#xff0c;无法理解 .vue 文件。 解决方法&#xff1a;在项目的根目录或者src文件夹下创建一个后辍为 文件名.d.ts 的文件&#xff0c;并写入一下内容&#xff1a; declare module *.vue {import { …...

基于若依ruoyi-nbcio支持flowable流程分类里增加流程应用类型

更多ruoyi-nbcio功能请看演示系统 gitee源代码地址 前后端代码&#xff1a; https://gitee.com/nbacheng/ruoyi-nbcio 演示地址&#xff1a;RuoYi-Nbcio后台管理系统 主要考虑到流程分很多种&#xff0c;普通的是OA流程&#xff0c;还有自定义业务流程&#xff0c;钉钉流程等…...

JS之同步异步promise、async、await

promise异步操作 Promise是异步编程的一种解决方案 JavaScript异步与同步解析 学习promise前我们先来了解下什么是异步&#xff1f; 基本概念&#xff1a; 消息队列中的任务分为宏任务与微任务;调用栈也可以称为主线程 首先我们要知道js是单线程语言&#xff0c;也就是说…...

【OpenCV • c++】自定义直方图 | 灰度直方图均衡 | 彩色直方图均衡

文章目录 一、什么是直方图二、自定义直方图三、灰度直方图均衡四、彩色直方图均衡一、什么是直方图 直方图广泛应用于很多计算机视觉处理当中。通过标记帧与帧之间显著的边缘和颜色的变化,可以检测视频中的场景变化。在每个兴趣点设置一个有相似特征的直方图所构成的“标签”…...

el-tree目录和el-table实现搜索定位高亮方法

需求&#xff1a;el-tree目录实现搜索查询el-table表格项&#xff0c;双击表格项根据yiZhuMLID||muLuID定位el-tree目录&#xff0c;并且高亮展示在可视化区域内&#xff0c;再重新根据el-tree目录的yiZhuMLID搜索刷新el-table表格&#xff0c;定位且高亮展示相对应的yiZhuMLID…...

linux常用指令

基础命令 cd&#xff1a;用于切换目录。例如&#xff0c;要从当前目录切换到/home/user目录&#xff0c;可以使用命令“cd /home/user”。ls&#xff1a;用于列出目录内容。例如&#xff0c;要列出当前目录的内容&#xff0c;可以使用命令“ls”。mkdir&#xff1a;用于创建目…...

C语言,指针的一些运算

若创建一个数组&#xff1a;int arr[10] 0; 用指针变量来储存数组首元素的地址&#xff1a;int* p arr,这里arr是数组名&#xff0c;表示首元素地址。 若p p 1或者p之后p本来指向数组首元素地址&#xff0c;就变成了指向第二个元素的地址&#xff0c;p n即指向第n 1个地…...

iPhone 如何强制重启

参考iPhone的官方使用手册 传送门 尤其当 iPhone 未响应&#xff0c;也无法将其关机再开机&#xff0c;此方法最有效&#xff1a; 按住调高音量按钮&#xff0c;然后快速松开。按住调低音量按钮&#xff0c;然后快速松开。按住侧边按钮。当 Apple 标志出现时&#xff0c;松开侧…...

数据结构--单链表操作

1.单链表的创建&#xff08;带头结点&#xff09; #include<stdlib.h> #define ElemType int typedef struct {//定义一个结点ElemType data;struct STU* next; }STU,*LinkList; bool InitList(LinkList& L) {L (STU*)malloc(sizeof(STU));//创建头结点if (L NUL…...

AlmaLinux (兼容centos)安装Geant4与ROOT

AlmaLinux 介绍 AlmaLinux OS 是一个开源、社区驱动的 Linux 操作系统&#xff0c;它填补了因 CentOS 稳定版本停止维护而留下的空白&#xff0c;同时更加强大。 安装 AlmaLinux 这个我用的是 windows 子系统进行安装 首先打开微软商店&#xff0c;然后搜索AlmaLinux&#…...

FPGA面试题(2)

一.同步复位和异步复位 同步复位&#xff1a;当clk有效时&#xff0c;复位才有效。优点&#xff1a;有利于时序分析&#xff0c;防止毛刺现象出现。缺点&#xff1a;复位信号必须大于时钟周期&#xff0c;大部分逻辑器件中D触发器都只有异步复位端口&#xff0c;需要在寄存器数…...

【C++ Primer Plus学习记录】指针——使用new来创建动态数组

目录 1.使用new创建动态数组 2.使用动态数组&#xff08;如何使用指针访问数组元素&#xff09; 如果程序只需要一个值&#xff0c;则可能会声明一个简单变量&#xff0c;因为对于管理一个小型数据对象来说&#xff0c;这样做比使用new和指针更简单。通常&#xff0c;对于大型…...

移动app广告变现,对接广告联盟还是选择第三方聚合广告平台?

作为互联网广告的载体&#xff0c;APP天生就比线下传统广告位更具优势&#xff0c;不受地域限制可以辐射到地球上的每一个角落&#xff0c;可以让广告获得更广的覆盖面。通过丰富的广告形式&#xff0c;精准的目标用户画像&#xff0c;也可以更好地实现品牌广告或效果广告的投放…...

ARM 按键控制 LED灯,蜂鸣器,风扇

main.c: #include "uart.h" #include "key_it.h" int main() {all_led_init();uart4_init();//串口初始化//中断初始化key_it_config();key3_it_config();buzzer_init();fan_init();while(1){//保证主程序不结束}return 0; }src/key_it.c: #include"…...

VirtualBox Ubuntu扩展虚拟机磁盘空间

关于Orical VM VirtualBox虚拟机安装了ubuntu linux系统&#xff0c;由于需要&#xff0c;磁盘空间不足&#xff0c;需要扩展磁盘空间&#xff0c;最终找到了一个非常简单的方法&#xff0c;上干货。 1、关闭虚拟机 2、运用VBoxManage命令扩展vdi文件的空间 打开windows的命…...

基于大模型的 UI 自动化系统

基于大模型的 UI 自动化系统 下面是一个完整的 Python 系统,利用大模型实现智能 UI 自动化,结合计算机视觉和自然语言处理技术,实现"看屏操作"的能力。 系统架构设计 #mermaid-svg-2gn2GRvh5WCP2ktF {font-family:"trebuchet ms",verdana,arial,sans-…...

基于距离变化能量开销动态调整的WSN低功耗拓扑控制开销算法matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.算法仿真参数 5.算法理论概述 6.参考文献 7.完整程序 1.程序功能描述 通过动态调整节点通信的能量开销&#xff0c;平衡网络负载&#xff0c;延长WSN生命周期。具体通过建立基于距离的能量消耗模型&am…...

MFC内存泄露

1、泄露代码示例 void X::SetApplicationBtn() {CMFCRibbonApplicationButton* pBtn GetApplicationButton();// 获取 Ribbon Bar 指针// 创建自定义按钮CCustomRibbonAppButton* pCustomButton new CCustomRibbonAppButton();pCustomButton->SetImage(IDB_BITMAP_Jdp26)…...

多模态商品数据接口:融合图像、语音与文字的下一代商品详情体验

一、多模态商品数据接口的技术架构 &#xff08;一&#xff09;多模态数据融合引擎 跨模态语义对齐 通过Transformer架构实现图像、语音、文字的语义关联。例如&#xff0c;当用户上传一张“蓝色连衣裙”的图片时&#xff0c;接口可自动提取图像中的颜色&#xff08;RGB值&…...

将对透视变换后的图像使用Otsu进行阈值化,来分离黑色和白色像素。这句话中的Otsu是什么意思?

Otsu 是一种自动阈值化方法&#xff0c;用于将图像分割为前景和背景。它通过最小化图像的类内方差或等价地最大化类间方差来选择最佳阈值。这种方法特别适用于图像的二值化处理&#xff0c;能够自动确定一个阈值&#xff0c;将图像中的像素分为黑色和白色两类。 Otsu 方法的原…...

Neo4j 集群管理:原理、技术与最佳实践深度解析

Neo4j 的集群技术是其企业级高可用性、可扩展性和容错能力的核心。通过深入分析官方文档,本文将系统阐述其集群管理的核心原理、关键技术、实用技巧和行业最佳实践。 Neo4j 的 Causal Clustering 架构提供了一个强大而灵活的基石,用于构建高可用、可扩展且一致的图数据库服务…...

Android第十三次面试总结(四大 组件基础)

Activity生命周期和四大启动模式详解 一、Activity 生命周期 Activity 的生命周期由一系列回调方法组成&#xff0c;用于管理其创建、可见性、焦点和销毁过程。以下是核心方法及其调用时机&#xff1a; ​onCreate()​​ ​调用时机​&#xff1a;Activity 首次创建时调用。​…...

为什么要创建 Vue 实例

核心原因:Vue 需要一个「控制中心」来驱动整个应用 你可以把 Vue 实例想象成你应用的**「大脑」或「引擎」。它负责协调模板、数据、逻辑和行为,将它们变成一个活的、可交互的应用**。没有这个实例,你的代码只是一堆静态的 HTML、JavaScript 变量和函数,无法「活」起来。 …...

BLEU评分:机器翻译质量评估的黄金标准

BLEU评分&#xff1a;机器翻译质量评估的黄金标准 1. 引言 在自然语言处理(NLP)领域&#xff0c;衡量一个机器翻译模型的性能至关重要。BLEU (Bilingual Evaluation Understudy) 作为一种自动化评估指标&#xff0c;自2002年由IBM的Kishore Papineni等人提出以来&#xff0c;…...

关于uniapp展示PDF的解决方案

在 UniApp 的 H5 环境中使用 pdf-vue3 组件可以实现完整的 PDF 预览功能。以下是详细实现步骤和注意事项&#xff1a; 一、安装依赖 安装 pdf-vue3 和 PDF.js 核心库&#xff1a; npm install pdf-vue3 pdfjs-dist二、基本使用示例 <template><view class"con…...