Android高仿360安全卫士--布局篇
来源:互联网 发布:淘宝优惠劵怎么用 编辑:程序博客网 时间:2024/05/15 18:54
原文:http://blog.csdn.net/wangjinyu501/article/details/8083373
这个Demo是可以左右滑动的,并且可以在布局文件中添加组件点击事件。主要是利用ViewPager类来实现的。
Activity程序:
package com.example.test;import java.util.ArrayList;import java.util.List;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.view.LayoutInflater;import android.view.Menu;import android.view.View;import android.widget.ImageView;import android.widget.LinearLayout;import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;public class TActivity extends Activity {private ViewPager mViewPager;private LinearLayout lin1, lin2;private Context cxt;private ViewPagerAdapter mAdapter;private List<View> mListViews;private LayoutInflater mInflater;boolean result = true; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); cxt = this; mListViews = new ArrayList<View>(); mInflater = getLayoutInflater(); mListViews.add(mInflater.inflate(R.layout.tab1, null)); mListViews.add(mInflater.inflate(R.layout.tab2, null)); mAdapter = new ViewPagerAdapter(mListViews); mViewPager = (ViewPager)findViewById(R.id.mViewPager); mViewPager.setAdapter(mAdapter); } /* * ViewPager适配器类 * 主要用到两个函数:instantiateItem和destroyedItem * instantiateItem主要实现新的画面的添加 * destroyedItem主要实现老的画面去处 */ private class ViewPagerAdapter extends PagerAdapter{ private List<View> list; public ViewPagerAdapter(List<View> list) {// TODO Auto-generated constructor stub this.list = list;} @Overridepublic int getCount() {// TODO Auto-generated method stubreturn list.size();}@Overridepublic Object instantiateItem(View container, int position) {// TODO Auto-generated method stub((ViewPager)container).addView(list.get(position),0);if (position == 0) {ImageView download_btn = (ImageView)container.findViewById(R.id.download_btn);download_btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubnew AlertDialog.Builder(TActivity.this) .setTitle("说明") .setMessage("单个页卡内按钮事件测试") .setNegativeButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { } }).show();}});}return list.get(position);}@Overridepublic void destroyItem(View container, int position, Object object) {// TODO Auto-generated method stub((ViewPager)container).removeView(list.get(position));}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {// TODO Auto-generated method stubreturn arg0 == arg1;} } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
main.xml
<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.ViewPager android:id="@+id/mViewPager" android:layout_width="match_parent" android:layout_height="match_parent" ></android.support.v4.view.ViewPager></RelativeLayout>
tab1.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/lin1" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:background="@drawable/rootblock_default_bg" android:orientation="horizontal" android:paddingBottom="30dp" android:paddingLeft="10dp" android:paddingTop="30dp" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:background="#FF7F24" > </LinearLayout> <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:layout_marginLeft="5dp" android:background="#FF7F24" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:background="#3399ff" > </LinearLayout> <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:layout_marginLeft="5dp" android:background="#3399ff" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:background="#3399ff" > </LinearLayout> <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:layout_marginLeft="5dp" android:background="#3399ff" > </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:orientation="horizontal" > <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:background="#953399ff" > </LinearLayout> <LinearLayout android:layout_width="108dp" android:layout_height="108dp" android:layout_marginLeft="5dp" android:background="#953399ff" > </LinearLayout> </LinearLayout> </LinearLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1"> <ImageView android:id="@+id/etra_btn" android:layout_width="36dp" android:layout_height="36dp" android:layout_marginBottom="10dp" android:layout_alignParentBottom="true" android:src="@drawable/rootblock_icon_add_bg" /> <ImageView android:id="@+id/set_btn" android:layout_width="36dp" android:layout_height="36dp" android:layout_above="@id/etra_btn" android:layout_marginBottom="10dp" android:src="@drawable/rootblock_icon_set_bg" /> <ImageView android:id="@+id/delete_btn" android:layout_width="36dp" android:layout_height="36dp" android:layout_above="@id/set_btn" android:layout_marginBottom="10dp" android:src="@drawable/rootblock_icon_clear_bg" /> <ImageView android:id="@+id/download_btn" android:layout_width="36dp" android:layout_height="36dp" android:layout_above="@id/delete_btn" android:layout_marginBottom="10dp" android:src="@drawable/rootblock_icon_download_bg" /> </RelativeLayout> </LinearLayout>
tab2.xml布局tab1.xml
工程文件:http://download.csdn.net/detail/zhaoshiqing7/4740665
- Android高仿360安全卫士--布局篇
- Android高仿360安全卫士--布局篇
- Android高仿360安全卫士--布局篇
- Android高仿360安全卫士--布局篇(一)
- Android高仿360安全卫士--布局篇(2)
- Android高仿360安全卫士--布局篇(2)
- Android高仿360安全卫士--布局篇(2)
- android手机安全卫士源码高仿360安全卫士
- [qt] 高仿360安全卫士
- C#制作高仿360安全卫士窗体<二>
- C#制作高仿360安全卫士窗体<二>
- C#制作高仿360安全卫士窗体<二>
- 【原创】高仿360安全卫士 9.2 界面 (纯qml实现)
- [android view]仿安全卫士的加速小球
- 高仿360手机卫士布局,用来学习布局
- 高仿苹果通讯录布局
- Android仿360卫士布局风格
- Android 仿 WP7 布局
- 无霍尔 无刷马达 接线
- nagios上增加nrpe模块达到监控主机CPU、内存、磁盘使用情况
- VC6.0 project settings
- Notepad++在英文操作系统下编译java
- Amazon Dynamo论文解读 — 技术介绍(转载)
- Android高仿360安全卫士--布局篇
- 如何过滤 adb logcat 输出
- nyoj 10 skilling
- MySQL创建索引
- Android ColorStateList使用
- 2012年的这些经典书目你读了没?
- 关掉Eclipse的自动代码提示
- linux网络编程常用头文件
- which must be escaped when used within the value 问题解决