Android课程设计第五天欢迎界面(滑动)和图形选择
2024-08-30 06:14:36
注意:课程设计只为完成任务,不做细节描述~
滑动界面
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>
最新文章
- javascript数据结构-栈
- 转载:ViewHolder为什么声明为static
- jQuery图片旋转展示收缩效果
- SU Demos-05Sorting Traces-03susorty
- opencv--图像轮廓检测
- JQ插件
- 解决VS2010无法打开,提示无法找到atl100.dll的方法
- js post提交页面
- poj 1905 Expanding Rods (数学 计算方法 二分)
- xtraScrollableControl 滚动条随鼠标滚动
- DevExpress之时间控件
- duilib绘制边框
- JS 拖动DIV 需要JQUERY 支持
- 重读 必须知道的.NET
- Codeforces Global Round 1 A~F
- ubuntu16.04安装mrpt
- Spring Boot 全局异常捕获
- C# Repeater、webdiyer:AspNetPager分页 AspNetPager分页样式
- SQL Server 常用函数使用方法(持续更新)
- learning docker steps(2) ----- docker contailner 初次体验
热门文章
- Linux fork函数具体图解-同一时候分析一道腾讯笔试题
- SELECT INSTR(120,0000); 真
- 【转】idea激活搭建授权服务器
- (linux)mmccard驱动的读写过程解析
- FZU1977 Pandora adventure —— 插头DP
- DedeCMS模板中用彩色tag做彩色关键词
- Java输入/输出(I/O)流的分类总结
- 一些优秀的iOS第三方库
- [Codeforces 914D] Bash and a Tough Math Puzzle
- [AHOI 2006] 上学路线