Fragment 实现的 分类 效果
Fragment 实现的 分类 效果
布局文件的信息:
- <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"
- android:layout_margin="0dp"
- android:background="#fffef9"
- tools:context=".MianActivity" >
- <!-- 1 替换的Fragment的内容! -->
- <LinearLayout
- android:id="@+id/contentfragment"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:orientation="vertical" >
- </LinearLayout>
- <!-- 2 底部的菜单 -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="bottom"
- android:layout_margin="0dp"
- android:layout_gravity="bottom"
- android:orientation="horizontal" >
- <Button
- android:id="@+id/articalmenu"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_margin="0dp"
- android:layout_weight="1"
- android:text="文章"
- />
- <Button
- android:id="@+id/forummenu"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:layout_margin="0dp"
- android:text="论坛"
- />
- <Button
- android:id="@+id/gamemenu"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:layout_margin="0dp"
- android:text="游戏"
- />
- </LinearLayout>
- </LinearLayout>
Activity 代码:
- package stu.love.game;
- import stu.love.artical.ArticalListFragment;
- import stu.love.forum.ForumFragment;
- import stu.love.utils.ImageCacheSDUtils;
- import android.app.ActivityManager;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.os.Bundle;
- import android.support.v4.app.FragmentActivity;
- import android.support.v4.app.FragmentManager;
- import android.support.v4.app.FragmentTransaction;
- import android.util.Log;
- import android.util.LruCache;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.Window;
- import android.widget.Button;
- import com.android.volley.RequestQueue;
- import com.android.volley.toolbox.ImageLoader.ImageCache;
- import com.android.volley.toolbox.Volley;
- /**
- * 3DM game 程序的 入口 測试类!
- *
- * */
- public class MianActivity extends FragmentActivity implements OnClickListener {
- private static String Tag= "MianActivity";
- // 菜单选项
- private Button articlemenu;
- private Button forummenu;
- private Button gamemenu;
- // 图片缓冲
- public RequestQueue queue;
- public ImageCache imageCache;
- public LruCache<String, Bitmap> lruCache;
- public Context context;
- // fragment
- private FragmentManager manager;
- private FragmentTransaction transaction;
- private ArticalListFragment articalListFragment;
- private ForumFragment forumFrgment;
- private GameFragment gameFragment;
- public MianActivity() {
- super();
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().requestFeature(Window.FEATURE_PROGRESS);
- setContentView(R.layout.activity_mian);
- // 1 初始化组件
- initComponet();
- // 2 初始化 frgment
- manager = getSupportFragmentManager();
- initArticalListFragment();
- }
- @Override
- protected void onResume() {
- // TODO Auto-generated method stub
- super.onResume();
- }
- /**
- * 1 初始化组件
- *
- * */
- private void initComponet() {
- articlemenu = (Button) this.findViewById(R.id.articalmenu);
- forummenu = (Button) this.findViewById(R.id.forummenu);
- gamemenu = (Button) this.findViewById(R.id.gamemenu);
- articlemenu.setOnClickListener(this);
- forummenu.setOnClickListener(this);
- gamemenu.setOnClickListener(this);
- /**
- * 1 开启异步任务 去下载数据!
- * 使用Volley框架!
- * 内部封装好了 异步任务!
- * 获取到数据之后 才干 设置 适配器!
- 自己定义Adapter
- * */
- // 获取请求队列
- context = getApplicationContext();
- queue = Volley.newRequestQueue(context);
- //获得系统的动态的剩余内存空间
- int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
- .getMemoryClass();
- //获取剩余的内存空间的/8
- final int cacheSize = 1024 * 1024 * memClass / 8;
- // 设置缓存的空间大小!
- lruCache = new LruCache<String, Bitmap>(cacheSize);
- // 初始化 图片的缓存!
- imageCache = new ImageCache() {
- public void putBitmap(String url, Bitmap bitmap) {
- // TODO Auto-generated method stub
- //设置缓存的路径
- Log.i(Tag, "--- 一级缓存 存入图片");
- lruCache.put(url, bitmap);
- if(ImageCacheSDUtils.getInstance().getBitmapData(url)== null)
- {
- byte[] data = ImageCacheSDUtils.getInstance().BitmapToByte(bitmap);
- Log.i(Tag, "--- 二级缓存 存入图片");
- ImageCacheSDUtils.getInstance().putBitmapData(url, data);
- }
- }
- public Bitmap getBitmap(String url) {
- // TODO Auto-generated method stub
- Log.i(Tag, "--- 一级缓存 取出图");
- Bitmap bitmap = lruCache.get(url);
- return bitmap;
- }
- };
- }
- /**
- * 2 事件的响应 替换 Fragment2 事件的响应 替换 Fragment
- */
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- transaction = manager.beginTransaction();
- switch (v.getId()) {
- case R.id.articalmenu:
- if (articalListFragment == null)
- articalListFragment = new ArticalListFragment(queue, imageCache, lruCache, context);
- transaction.replace(R.id.contentfragment, articalListFragment,"articalListFragment");
- transaction.addToBackStack("articalListFragment");
- break;
- case R.id.forummenu:
- if (forumFrgment == null)
- forumFrgment = new ForumFragment();
- transaction.replace(R.id.contentfragment, forumFrgment,"forumFrgment");
- transaction.addToBackStack("forumFrgment");
- break;
- case R.id.gamemenu:
- if (gameFragment == null)
- gameFragment = new GameFragment(queue, imageCache, lruCache, context);
- transaction.replace(R.id.contentfragment, gameFragment,"gameFragment");
- transaction.addToBackStack("gameFragment");
- break;
- }
- // fragment 的替换!
- transaction.commit();
- }
- // 3 初始化 Fragment 第一次载入的时候数据!
- public void initArticalListFragment()
- {
- transaction = manager.beginTransaction();
- articalListFragment = new ArticalListFragment(queue, imageCache, lruCache, context);
- transaction.add(R.id.contentfragment, articalListFragment,"articalListFragment");
- transaction.addToBackStack("articalListFragment");
- // 由于这里 ,没有 commit 所以 不能show data!
- transaction.commit();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.mian, menu);
- return true;
- }
- }
Fragment 实现的 分类 效果的更多相关文章
- 使用ViewPager+Fragment实现选项卡切换效果
实现效果 本实例主要实现用ViewPage和Fragment实现选项卡切换效果,选项卡个数为3个,点击选项卡或滑动屏幕会切换Fragment并实现选项卡下方下边框条跟随移动效果. 本程序用androi ...
- Android - FragmentTabHost 与 Fragment 制作页面切换效果
使用 FragmentTabHost 与 Fragment 制作页面切换效果 API 19 TabHost已经不建议使用了.用 FragmentTabHost 来代替TabHost.实际上 Fragm ...
- Android - TabHost 与 Fragment 制作页面切换效果
Android - TabHost 与 Fragment 制作页面切换效果 Android API 19 , API 23 三个标签页置于顶端 效果图: 在文件BoardTabHost.java中定义 ...
- python + sklearn ︱分类效果评估——acc、recall、F1、ROC、回归、距离
之前提到过聚类之后,聚类质量的评价: 聚类︱python实现 六大 分群质量评估指标(兰德系数.互信息.轮廓系数) R语言相关分类效果评估: R语言︱分类器的性能表现评价(混淆矩阵,准确率,召回率,F ...
- CNN结构:图片风格分类效果已成(StyleAI)
CNN结构:图片风格分类效果已成.可以在色彩空间对图片风格进行分类,并进行目标分类. StyleAI构架:FasterRCnn + RandomTrees 为何不使用MaskRCNN? MaskRCN ...
- NavigationDrawer+Fragment实现侧滑菜单效果
学习了NavigationDrawer 官方Support包中的SlidingMenu版本,练了下手.用到了ListView中item不同的布局 以后会升级加上ViewPager和GridView实现 ...
- Android下fragment切换的动画效果
网上看到的例子,转过来记录一下,学习一下,感谢原作者的辛勤编码,效果非常好 基于Android3.0新增的动画api,效果很赞 共21种动画效果: <item>X轴缩放</item& ...
- django实现日期分类效果
日期分类效果图 实现功能:能够按照月份进行分类,统计每个月份的文章数量,没有文章的月份不显示.点击每栏可以链接的当月的文章列表. 每月文章列表可以使用django的通用视图MonthArticleVi ...
- Android viewPager+fragment实现滑页效果
先上图,手指在手机向左或者向右滑就可以实现相应的页面切换. 先看activity_main.xml文件,非常简单,主要是三个标题TextView和viewpager <?xml version= ...
随机推荐
- 【Linux】JDK+Eclipse 搭建C/C++开发环境
注:本文所提供的参考示例是在CentOS Linux环境下的安装,不保证适用于其他版本的Linux系统. · 安装前的注意事项 编译源代码是需要对应的代码编译工具的,本文中安装的Eclipse只 ...
- 如何保证对象线程内唯一:数据槽(CallContext)
CallContext 是类似于方法调用的线程本地存储区的专用集合对象,并提供对每个逻辑执行线程都唯一的数据槽.数据槽不在其他逻辑线程上的调用上下文之间共享.当 CallContext 沿执行代码路径 ...
- 1.9 Python基础知识 - 数值运算
一.数值运算 在Python中有丰富的算术运算,这使得Python在科学计算领域有着很高的地位,Python可以提供包括四则运算在内的各种算术运算. 算术运算符 运算符 含义 说明 优先级 实例 ...
- mpvue 开发小程序
转换成vue语法, 小程序中原生的事件用@ 原生的属性用:
- nginx 实现跨域
nginx 添加头部跨域. location / { add_header 'Access-Control-Allow-Origin' '*'; //允许的域 add_header 'Access-C ...
- JAVA基础数据类型
JAVA的数据类型粗略分两种 1.基本数据类型 整数类型: byte,short,int,long 浮点类型: float,double 字符类型: char 布尔类型: boolean 基本语法格式 ...
- linux 配置全局jdk环境
1.在usr/local下新建software文件夹(mkdir software),将下载的jdk和tomcat放在此文件夹下 2.解压 tar -xzvf jdk-8u191-linux-x64. ...
- 带你玩转Visual Studio——性能分析与优化
找到性能瓶颈 二八法则适合很多事物:最重要的只占其中一小部分,约20%,其余80%的尽管是多数,却是次要的.在程序代码中也是一样,决定应用性能的就那20%的代码(甚至更少).因此优化实践中,我们将精力 ...
- EBS OAF开发中实体对象和视图对象的属性设置器
EBS OAF开发中实体对象和视图对象的属性设置器 (版权声明.本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 源文: Home > Oracle ...
- ActiveReports 9实战教程(2): 准备数据源(设计时、执行时)
在上讲中<ActiveReports 9实战教程(1): 手把手搭建好开发环境Visual Studio 2013 社区版>,我们已经结合Visual Studio 2013搭建好了Act ...