转自:http://blog.csdn.net/wangjinyu501/article/details/8083373

最近模仿360手机卫士,做了一个Demo。看了一下360的布局文件,发现它是自定义的View,而不是官方提供的基本组件的组合。效果如下图所示:

这个Demo是可以左右滑动的,并且可以在布局文件中添加组件点击事件。主要是利用ViewPager类来实现的。

public class Main360Activity extends Activity
{private ViewPager awesomePager;private LinearLayout lin1, lin2;private Context cxt;private AwesomePagerAdapter awesomeAdapter;private LayoutInflater mInflater;private List<View> mListViews;boolean result = true;public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main360);cxt = this;lin1 = (LinearLayout) findViewById(R.id.lin1);lin2 = (LinearLayout) findViewById(R.id.lin2);awesomeAdapter = new AwesomePagerAdapter();awesomePager = (ViewPager) findViewById(R.id.awesomepager);awesomePager.setAdapter(awesomeAdapter);mListViews = new ArrayList<View>();mInflater = getLayoutInflater();mListViews.add(mInflater.inflate(R.layout.tab360, null));mListViews.add(mInflater.inflate(R.layout.tab360, null));}private class AwesomePagerAdapter extends PagerAdapter{public int getCount(){return mListViews.size();}public Object instantiateItem(View collection, int position){((ViewPager) collection).addView(mListViews.get(position), 0);if (position == 0){ImageView download_btn = (ImageView) collection.findViewById(R.id.download_btn);download_btn.setOnClickListener(new View.OnClickListener(){public void onClick(View v){//                        if (result == true)
//                      {
//
//                          lin1.scrollBy(0, 0);
//
//                          lin1.scrollTo(80, 0);
//
//                          lin1.setPadding(0, 30, 0, 30);
//
//                          lin2.setVisibility(View.VISIBLE);
//
//                          result = false;
//
//                      } else
//                      {
//
//                          lin1.setPadding(10, 30, 0, 30);
//
//                          lin1.scrollBy(80, 0);
//
//                          lin1.scrollTo(0, 0);
//
//                          lin2.setVisibility(View.GONE);
//
//                          result = true;
//                      }}});// }// });} else{ImageView download_btn = (ImageView) collection.findViewById(R.id.download_btn);download_btn.setOnClickListener(new View.OnClickListener(){public void onClick(View v){new AlertDialog.Builder(Main360Activity.this).setTitle("说明").setMessage("单个页卡内按钮事件测试").setNegativeButton("确定",new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialog,int which){}}).show();}});}return mListViews.get(position);}public void destroyItem(View collection, int position, Object view){((ViewPager) collection).removeView(mListViews.get(position));}public boolean isViewFromObject(View view, Object object){return view == (object);}public void finishUpdate(View arg0){}public void restoreState(Parcelable arg0, ClassLoader arg1){}public Parcelable saveState(){return null;}public void startUpdate(View arg0){}}// @Override// public boolean onCreateOptionsMenu(Menu menu)// {// getMenuInflater().inflate(R.menu.activity_main, menu);// return true;// }
}

main360.xml的内容如下:

<?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" ><android.support.v4.view.ViewPagerandroid:id="@+id/awesomepager"android:layout_width="match_parent"android:layout_height="match_parent" ></android.support.v4.view.ViewPager></RelativeLayout>

tab360.xml的内容如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent" ><LinearLayoutandroid:id="@+id/lin1"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/background"android:baselineAligned="false"android:orientation="horizontal"android:paddingBottom="30dp"android:paddingLeft="10dp"android:paddingTop="30dp" ><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:orientation="vertical" ><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:orientation="horizontal" ><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:background="#FF7F24" ></LinearLayout><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:layout_marginLeft="5dp"android:background="#FF7F24" ></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:orientation="horizontal" ><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:background="#3399ff" ></LinearLayout><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:layout_marginLeft="5dp"android:background="#3399ff" ></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:orientation="horizontal" ><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:background="#3399ff" ></LinearLayout><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:layout_marginLeft="5dp"android:background="#3399ff" ></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:orientation="horizontal" ><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:background="#953399ff" ></LinearLayout><LinearLayoutandroid:layout_width="108dp"android:layout_height="108dp"android:layout_marginLeft="5dp"android:background="#953399ff" ></LinearLayout></LinearLayout></LinearLayout><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_weight="1"android:orientation="vertical" ><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="fill_parent" ><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:orientation="vertical" ><ImageViewandroid:id="@+id/download_btn"android:layout_width="36dp"android:layout_height="36dp"android:src="@drawable/a" /><ImageViewandroid:id="@+id/delete_btn"android:layout_width="36dp"android:layout_height="36dp"android:layout_marginTop="20dp"android:src="@drawable/b" /><ImageViewandroid:id="@+id/set_btn"android:layout_width="36dp"android:layout_height="36dp"android:layout_marginTop="20dp"android:src="@drawable/c" /><ImageViewandroid:id="@+id/etra_btn"android:layout_width="36dp"android:layout_height="36dp"android:layout_marginTop="20dp"android:src="@drawable/ic_launcher" /></LinearLayout></RelativeLayout></LinearLayout></LinearLayout><LinearLayoutandroid:id="@+id/lin2"android:layout_width="wrap_content"android:layout_height="fill_parent"android:layout_gravity="right"android:background="#000000"android:orientation="vertical"android:visibility="gone" ><TextViewandroid:layout_width="80dp"android:layout_height="fill_parent"android:text="dddddddddddd" /></LinearLayout></FrameLayout>

关于Viewpager的用法大家可以去看一下资料,在此不再详述。这个tab.xml就是用来切换的布局,也就是左右滑动的布局文件。我们在这里用来两个切换布局,可以根据自己的需求动态增删。但是,仔细看官方的程序我们发现,它的背景是不变的。就这需要使用其他的方法来实现,也就是自定义View,下一节将讲述如何自定义View来实现。

需要源码的朋友可以留一下你的邮箱。

其他UI设计日志链接如下:

仿微信导航

仿微信主界面

仿QQ登陆

仿QQ空间

Android高仿360安全卫士--布局篇相关推荐

  1. Android高仿360安全卫士--布局篇(2)

     一.概述 之前写过一篇文章也是关于360安全卫士布局的,发现有很多朋友比较感兴趣,鉴于此这次继续再完善一下.先说一下思路: 1.继续使用ViewPager来滑动切换页面 2.使用GridView来显 ...

  2. C#制作高仿360安全卫士窗体(三)

    距上篇C#制作高仿360安全卫士窗体(二)也将近一个多月了,这个月事情还是像往常一样的多.不多我也乐在其中,毕竟我做的是我喜欢做的东西.今天特地抽空把怎么制作文本框写一下.同时也希望有爱好这些玩意的同 ...

  3. C#制作高仿360安全卫士窗体二

    继上次C#制作高仿360安全卫士窗体<一>发布之后响应还不错,我的博客放肆雷特也来了不少的新朋友,在这里先谢谢大家的支持!我自己也反复看了一下觉得对不起大家,写的非常乱而且很少文字介绍.在 ...

  4. C#制作高仿360安全卫士窗体一

    开始写这一系列博客之前先要向大家说声抱歉,放肆雷特建立很久却很少有更新.当然博客人气也不旺,大部分都是看的人多评论收藏的人少.一直想要改变这种状态,正好赶上了最近工作上做了一个高仿360安全卫士窗体. ...

  5. C#制作高仿360安全卫士窗体(四)- 水晶按钮

    项目越来越紧,我也乐此不疲.自从上次C#制作高仿360安全卫士窗体(三)出来之后,就开始有一些人在说为什么还在坚持写这么落后的东西.我想说的是,我是从事企业信息化工作的,所有程序都只对内部使用.所以只 ...

  6. android手机安全卫士源码高仿360安全卫士

    下载地址:http://download.csdn.net/detail/lengyanyue2014/7993363 运行截图: 源码目录 │  .classpath │  .project │   ...

  7. (android高仿系列)今日头条 --新闻阅读器 (三) 完结 、总结 篇

    从写第一篇今日头条高仿系列开始,到现在已经过去了1个多月了,其实大体都做好了,就是迟迟没有放出来,因为我觉得,做这个东西也是有个过程的,我想把这个模仿中一步一步学习的过程,按照自己的思路写下来,在根据 ...

  8. android仿微信充值布局,Android 高仿微信支付数字键盘功能

    现在很多app的支付.输入密码功能,都已经开始使用自定义数字键盘,不仅更加方便.其效果着实精致. 下面带着大家学习下,如何高仿微信的数字键盘,可以拿来直接用在自身的项目中. 先看下效果图: 1. 自定 ...

  9. 高仿360手机卫士——Android源码

    高仿360手机卫士 高仿360手机卫士界面android源码,左右滑动效果,超炫. 下载地址:http://www.devstore.cn/code/info/1173.html 运行截图:    热 ...

最新文章

  1. 将图片的每个像素进行分类
  2. 《Adobe InDesign CS5中文版经典教程》—第1课1.9节查找InDesign帮助资源
  3. python入门视频教程推荐-Python入门视频看哪个好?适合初学者的教学视频推荐
  4. [VB] Option Explicit
  5. grafana—— worldPing APP 中文
  6. ACM-ICPC 2018 沈阳赛区现场赛 K. Let the Flames Begin (约瑟夫环问题)
  7. 第三十五章 大唐工厂主
  8. 禅道外部消息提示_Spring Boot中文参考指南(2.1.6)34、消息传递
  9. Android Stdio4.1.1版本使用问题
  10. 在mini2440上面搞定CC2500驱动
  11. 计算机攻击方式有哪些,常用的dos攻击方式是什么
  12. 网站服务器后缀名,服务器域名,域名后缀
  13. assume用法及意思_assume的用法总结大全
  14. 柳永 天涯 青砚1989
  15. 年底了,你总结了吗?我先来。
  16. 阿里云存储oss依赖报错解决方法
  17. 墨哥视角,微软大八系,能大发么?(一)——surface
  18. MacOS安装npm
  19. C# Jason 序列化到文件 和从文件反序列化到对象
  20. Codeforces1221 B. Knights(构造)

热门文章

  1. 独立成分分析ICA在MATLAB中的实现
  2. 【MySQL】【TypeScript 编写 Vue】【人工智能入门】【深度学习】| Chat · 预告
  3. python的del方法_关于python:__ del__方法是什么,如何调用它?
  4. 贴片轻触开关路线难题
  5. 11个国外购买WordPress主题的网站推荐
  6. 数据结构之反黄牛火车票订票系统
  7. 世界公认最健康的作息时间表,今后就照这个来~
  8. java实现银行新用户现金业务办理(数据库)
  9. DBeaver导入数据中文乱码问题
  10. 易语言怎么加密才不暴露服务器ip,如何实现服务器IP的隐藏