Android课程设计第五天欢迎界面(滑动)和图形选择
注意:课程设计只为完成任务,不做细节描述~
滑动界面
package com.example.myapplication; import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import Utils.AboutVersion; public class MainActivity extends AppCompatActivity {
private Handler handle=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//得到Handler的对象,默认接收消息
handle = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int a=msg.what;
AboutVersion aboutAboutVersion = new AboutVersion();
int ver= aboutAboutVersion.getSaveVersion(MainActivity.this);
int saveServison= aboutAboutVersion.getSaveVersion(MainActivity.this);
if(ver==saveServison){
//没有更新 跳转到主界面
Intent intent = new Intent(MainActivity.this,HomeActivity.class);
startActivity(intent);
}else{
aboutAboutVersion.saveVersion(MainActivity.this);
Intent intent=new Intent(MainActivity.this,WelcomeActivity.class);
//貌似获取版本失败了
startActivity(intent);
}
}
};
new FirstThread().start();
}
class FirstThread extends Thread{
@Override
public void run() {
super.run();
try {
Thread.sleep(1000);
handle.sendEmptyMessage(11);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
package com.example.myapplication; import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class HomeActivity extends AppCompatActivity {
private Button btn_first,btn_theme,btn_person;
private FirstFragment first;
private ThemFragment ThemFragment;
private PersonFragment PersonFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initView();
//开启碎片管理器
FragmentManager manager =getFragmentManager();
//开启碎片事物
FragmentTransaction action =manager.beginTransaction();
first = new FirstFragment();
//将fragment的对象添加到帧布局中
action.add(R.id.frame,first);
action.commit();
}
public void initView(){
btn_first= (Button) findViewById(R.id.firstPage);
btn_theme= (Button) findViewById(R.id.mainTheme);
btn_person=(Button) findViewById(R.id.My);
btn_first.setSelected(true);
btn_person.setSelected(false);
btn_theme.setSelected(false);
}
/*
该方法是由布局文件的Onclick属性指定过来的,修饰符需要pubilc,方法名需要和Onclick的值相同
*/ public void Click(View v){
btn_first.setSelected(false);
btn_person.setSelected(false);
btn_theme.setSelected(false);
FragmentManager mananger = getFragmentManager();
FragmentTransaction action=mananger.beginTransaction();
switch (v.getId()){
case R.id.firstPage:
btn_first.setSelected(true);
if(first==null){
first= new FirstFragment();
}
action.replace(R.id.frame,first);
action.commit();
break;
case R.id.mainTheme:
btn_theme.setSelected(true);
if(ThemFragment ==null){
ThemFragment =new ThemFragment();
}
action.replace(R.id.frame, ThemFragment);
action.commit();
break;
case R.id.My:
btn_person.setSelected(true);
if(PersonFragment ==null){
PersonFragment =new PersonFragment();
}
action.replace(R.id.frame, PersonFragment);
action.commit();
break;
}
} }
package com.example.myapplication; import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by 樱花落舞 on 2017/6/15.
*/ public class PersonFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_person,container,false);
return view;
}
}
package com.example.myapplication; import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup; /**
* Created by 樱花落舞 on 2017/6/15.
*/ public class ThemFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_them,container,false);
return view;
}
}
package com.example.myapplication; import android.app.Activity;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView; import Adapter.WeclomeAdapter; /**
* Created by 樱花落舞 on 2017/6/13.
* 1.创建java文件继承Activity或者activity子类
* 2.重写OnCreate()方法
* 3.添加布局文件
* 4.在清单文件中进行注册
*/ public class WelcomeActivity extends Activity {
private ViewPager pager;
private int images[]={R.mipmap.b,R.mipmap.c,R.mipmap.a};
private ImageView views[]=new ImageView[3];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
pager= (ViewPager) findViewById(R.id.viewapger);
for(int i=0;i<3;i++){
ImageView view=new ImageView(WelcomeActivity.this);
view.setImageResource(images[i]);
views[i]=view;
}
WeclomeAdapter adapter= new WeclomeAdapter(views);
pager.setAdapter(adapter);
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:color="#ffff0000"/> <item android:color="#0fffff" android:state_selected="false"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@mipmap/ico_screen" /> <item android:drawable="@mipmap/ico_screen_pred" android:state_selected="false"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@mipmap/ico_personal_pred"/>
<item android:drawable="@mipmap/ico_personal" android:state_selected="false"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myapplication.HomeActivity"> <LinearLayout
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="#0ccfff"
>
<Button
android:id="@+id/firstPage"
android:drawableTop="@drawable/picture"
android:text="首页"
style="@style/bottomStyle"
android:textColor="@color/barcolor"
android:onClick="Click"
/>
<Button
android:id="@+id/mainTheme"
style="@style/bottomStyle"
android:drawableTop="@drawable/picture2"
android:text="专题"
android:textColor="@color/barcolor"
android:onClick="Click"
/>
<Button
android:id="@+id/My"
style="@style/bottomStyle"
android:drawableTop="@drawable/picture3"
android:text="我的"
android:textColor="@color/barcolor"
android:onClick="Click"
/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame"
android:layout_above="@id/bottomBar"
></FrameLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myapplication.MainActivity"
android:background="@mipmap/xiaomai"> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewapger"> </android.support.v4.view.ViewPager>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#075f3a">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list"
></ListView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8b844c"> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4c648b"> </RelativeLayout>
<resources> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="bottomStyle">
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:background">@null</item>
<item name="android:color">@color/barcolor</item>
<item name="android:textSize">12sp</item>
<item name="android:paddingTop">8dp</item>
</style>
</resources>
Android课程设计第五天欢迎界面(滑动)和图形选择的更多相关文章
- Android课程设计第六天欢迎界面(跳转)
注意:课程设计只为完成任务,不做细节描述~ package com.example.myapplication; import android.app.Activity; import android ...
- Android课程设计第二天界面排版
注意:课程设计只为完成任务,不做细节描述~ 老师叫我们做一个这个样子,然后.. <?xml version="1.0" encoding="utf-8"? ...
- Android课程设计——博学谷1.0
本文讲述了如何应用大三下学期智能移动终端开发技术课程所学知识,完成包含服务器端.客户端程序的应用——博学谷登录模块的开发,结合java语言基本知识,例如:字符串.列表.类.数据库读写等,设计.实现一个 ...
- Android课程设计第四天ListView运用
注意:课程设计只为完成任务,不做细节描述~ 效果图 <?xml version="1.0" encoding="utf-8"?> <Relat ...
- Android课程设计第三天帧动画区间动画
注意:课程设计只为完成任务,不做细节描述~ 点火是帧动画,发射是区间动画,于是 <?xml version="1.0" encoding="utf-8"? ...
- Android课程设计第一天Android Studio安装
注意:课程设计只为完成任务,不做细节描述~ 学校有一个Android的课设,所以顺便把Android Studio安装了上去. 实际上安装过程并不复杂,只有几个地方需要注意~ 安装包可以去http:/ ...
- python课程设计笔记(五) ----Resuests+BeautifulSoup (爬虫入门)
官方参考文档(中文版): requests:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html beautifulsou ...
- 【Android UI设计与开发】9:滑动菜单栏(一)开源项目SlidingMenu的使用和示例
一.SlidingMenu简介 相信大家对SlidingMenu都不陌生了,它是一种比较新的设置界面或配置界面的效果,在主界面左滑或者右滑出现设置界面效果,能方便的进行各种操作.很多优秀的应用都采用了 ...
- 【Android UI设计与开发】10:滑动菜单栏(二)SlidingMenu 动画效果的实现
其实就是在显示菜单栏时,有个动画的效果.代码比较简单,下面进行说明. 1.效果图如下,手机上查看效果更佳 2.代码实现,这里只讲解动画效果的实现,具体代码可在源代码中查看 <1> 先定义一 ...
随机推荐
- node封装mysql模块
node是基于异步的,因此在进行数据库查询操作的通常是通过回调来操作查询结果.但是在有了es7的async/await,基本不再需要回调了,所以本篇是基于async/await对mysql进行一次操作 ...
- 关于 SWT 的UI线程和非UI线程
要理解UI线程,先要了解一下“消息循环”这个概念.链接是百度百科上的条目,简单地说,操作系统把用户界面上的每个操作都转化成为对应的消息,加入消息队列.然后把消息转发给对应的应用程序(一般来说,就是活动 ...
- kaminari分页插件样式
修改国际化文件,zh-cn views: pagination: first: "首页" last: "尾页" previous: "上一页" ...
- Hive两种访问方式:HiveServer2 和 Hive Client
老版HiveClient: 要求比较多,需要Hive和Hadoop的jar包,各配置环境. HiveServer2: 使得与YARN和HDFS的连接从Client中独立出来, ...
- DataSnap Mobile Client Tutorial
One of my customers was having some difficulty following the DataSnap tutorial which can be found he ...
- (linux)SD卡初始化-mmc_sd_init_card函数
为了学习SD/SDIO协议,看了一下linux中初始化SD卡的流程,结合代码更容易SD初始化是怎么做的. 下面图截自:"SD Specifications Part 1 Physical ...
- HDU1964 Pipes —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1964 Pipes Time Limit: 5000/1000 MS (Java/Others) Memory Limi ...
- for、while循环(java基础知识四)
1.循环结构概述和for语句的格式及其使用 * 什么是循环结构 循环语句可以在满足循环条件的情况下,反复执行某一段代码,这段被重复执行的代码被称为循环体语句,当反复执行这个循环体时,需要在合适的时候把 ...
- g00 网站说明
最近在做dns tunnel检测,发现了一堆类似这样的域名:c-6rtwjumjzx7877x24uwjkjwjshjx78x2eywzx78yjx2ehtr.g00.medicinenet.com ...
- registerWithTouchDispatcher 注册单点触摸事件
Doc: If isTouchEnabled, this method is called onEnter. Override it to change the way CCLayer receive ...