-------------------------------------------------------------Activity
package com.example.view;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import com.example.group.SomeGroupActivity;
import com.example.tylxdz.MainActivity;
import com.example.tylxdz.PersonInfoActivity;
import com.example.tylxdz.R;
import com.example.tylxdz.ShoppingViewActivity;
/**
* 项目框架--4的页面切换
*
* @author hlzby 主要功能实现:
* 1.底部框架思路:当没有触摸屏幕时、隐藏框架 当触摸时、显示框架
* 2.使用TabHost底部放置
*
* 为实现界面:3个静态界面
* 1.个人中心--订单
*/
public class FirstView extends TabActivity implements OnCheckedChangeListener,
OnClickListener {
private TabHost tabHost;// 声明tabhost对象
RadioGroup radioGroup;// 主界面布局
FrameLayout updatatv;
private int flag = 0;// 判断ImagButton的Enable-false/true
int back;
LinearLayout first_l_btn;
ImageButton btn_loss;
Button button1, button2, button3, button4, button5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.first_view);
init();
}
private void init() {
getTabView();
radioGroup = (RadioGroup) this.findViewById(R.id.main_tab_group);
radioGroup.setOnCheckedChangeListener(this);
first_l_btn = (LinearLayout) findViewById(R.id.first_l_btn);
button1 = (Button) findViewById(R.id.bt1);
button2 = (Button) findViewById(R.id.bt2);
button3 = (Button) findViewById(R.id.bt3);
button4 = (Button) findViewById(R.id.bt4);
button5 = (Button) findViewById(R.id.bt5);
btn_loss = (ImageButton) findViewById(R.id.btn_loss);
btn_loss.setOnClickListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.main_tab_first:
tabHost.setCurrentTabByTag("首页");
break;
case R.id.main_tab_second:
tabHost.setCurrentTabByTag("分类");
break;
case R.id.main_tab_thread:
tabHost.setCurrentTabByTag("购物车");
break;
case R.id.main_tab_settings:
tabHost.setCurrentTabByTag("个人中心");
break;
}
}
/**
* 设置TabHost属性
*/
private void getTabView() {
tabHost = this.getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, MainActivity.class);
spec = tabHost.newTabSpec("首页").setIndicator("首页").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SomeGroupActivity.class);
spec = tabHost.newTabSpec("分类").setIndicator("分类").setContent(intent);
tabHost.addTab(spec);
//
intent = new Intent().setClass(this, MainActivity.class);
spec = tabHost.newTabSpec("中间").setIndicator("中间").setContent(intent);
tabHost.addTab(spec);
//
intent = new Intent().setClass(this, ShoppingViewActivity.class);
spec = tabHost.newTabSpec("购物车").setIndicator("购物车").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, PersonInfoActivity.class);
spec = tabHost.newTabSpec("个人中心").setIndicator("个人中心")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_loss:
System.out.println("点击了中间...");
radioGroup.setVisibility(View.GONE);
break;
}
}
/**
* onTouchEvent();
* 被GridView的点击事件所拦截 如果触摸屏幕 显示 否则 隐藏
* down--弹出底部控件
* move--隐藏
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch(ev.getAction()){
case MotionEvent.ACTION_DOWN:
System.out.println("起始位置为:"+"("+ev.getX()+" , "+ev.getY()+")");
radioGroup.setVisibility(View.VISIBLE);
break;
case MotionEvent.ACTION_MOVE:
radioGroup.setVisibility(View.GONE);
break;
case MotionEvent.ACTION_UP:
System.out.println(("最后位置为:"+"("+ev.getX()+" , "+ev.getY()+")"));
}
return super.dispatchTouchEvent(ev);
};
}
------------------------------------------------------------------------xml
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstView" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:visibility="gone" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" >
<RadioGroup
android:id="@+id/main_tab_group"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal"
android:weightSum="5" >
<RadioButton
android:id="@+id/main_tab_first"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:checked="true"
android:drawableTop="@drawable/ic_launcher"
android:gravity="center"
android:text="首页"
android:textSize="9dp" />
<RadioButton
android:id="@+id/main_tab_second"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/ic_launcher"
android:gravity="center"
android:text="分类"
android:textSize="9dp" />
<ImageButton
android:id="@+id/btn_loss"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@android:color/transparent"
android:src="@drawable/paintvp1"
android:textSize="9dp" />
<RadioButton
android:id="@+id/main_tab_thread"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/ic_launcher"
android:gravity="center"
android:text="购物车"
android:textSize="9dp" />
<RadioButton
android:id="@+id/main_tab_settings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/ic_launcher"
android:gravity="center"
android:text="个人中心"
android:textSize="9dp" />
</RadioGroup>
<LinearLayout
android:id="@+id/first_l_btn"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:visibility="gone" >
<!-- 显示提醒信息的button android:layout_weight=1 是3个butto,平分手机界面的宽度 -->
<Button
android:id="@+id/bt1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" />
<!-- 占位置的button,以便适应不同分辨率手机 -->
<Button
android:id="@+id/bt2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" />
<!-- 占位置的button,以便适应不同分辨率手机 -->
<Button
android:id="@+id/bt3"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" />
<Button
android:id="@+id/bt4"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" />
<Button
android:id="@+id/bt5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
--------------------------------------------------------------Activity【第一个view】
package com.example.tylxdz;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.msfl.MSFLActivity;
import com.example.msfl.MSFL_In_Activity;
/**
* App首页
*
* @author hlzby
*
*/
public class MainActivity extends Activity implements OnClickListener,
OnItemClickListener {
// GridView
GridView mine_gDview;
/**
* 顶部滑动
*/
Gallery gallery;
ImageView iv;
private int[] imageId = { R.drawable.mpage0, R.drawable.mpage1,
R.drawable.mpage2, R.drawable.mpage3 };// --顶部实现轮播的照片资源
int index;// 下标--定义
// TextView --美食分类--四个点击跳转事件
TextView tv_toA1, tv_toA2, tv_toA3, tv_toA4;
ImageView iv_onclick1, iv_onclick2, iv_onclick3, iv_onclick4, iv_onclick5,
iv_onclick6;// 六个照片--显示信息
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
//初始化控件
mine_gDview = (GridView) findViewById(R.id.mine_gDview);
gallery = (Gallery) findViewById(R.id.gallery);
//--的跳转控件
tv_toA1 = (TextView) findViewById(R.id.tv_toA1);
tv_toA2 = (TextView) findViewById(R.id.tv_toA2);
tv_toA3 = (TextView) findViewById(R.id.tv_toA3);
tv_toA4 = (TextView) findViewById(R.id.tv_toA4);
// --点击进入信息详情
iv_onclick1 = (ImageView) findViewById(R.id.iv_onclick1);
iv_onclick2 = (ImageView) findViewById(R.id.iv_onclick2);
iv_onclick3 = (ImageView) findViewById(R.id.iv_onclick3);
iv_onclick4 = (ImageView) findViewById(R.id.iv_onclick4);
iv_onclick5 = (ImageView) findViewById(R.id.iv_onclick5);
iv_onclick6 = (ImageView) findViewById(R.id.iv_onclick6);
gallery.setAdapter(adapter);
gallery.setSelection(0);// imageId.length / 2 --选择从第一个开始
timer.schedule(task, 2500, 2500);// 设置轮播执行时间
MineAdapter adapter = new MineAdapter(this);// 加载GridView的适配器
mine_gDview.setAdapter(adapter);
mine_gDview.setSelector(new ColorDrawable(Color.TRANSPARENT));
mine_gDview.setOnItemClickListener(this);
tv_toA1.setOnClickListener(this);
tv_toA2.setOnClickListener(this);
tv_toA3.setOnClickListener(this);
tv_toA4.setOnClickListener(this);
iv_onclick1.setOnClickListener(this);
iv_onclick2.setOnClickListener(this);
iv_onclick3.setOnClickListener(this);
iv_onclick4.setOnClickListener(this);
iv_onclick5.setOnClickListener(this);
iv_onclick6.setOnClickListener(this);
}
BaseAdapter adapter = new BaseAdapter() {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
iv = new ImageView(MainActivity.this);
iv.setScaleType(ImageView.ScaleType.FIT_XY);
iv.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TypedArray typedArray = obtainStyledAttributes(R.styleable.Gallery);
iv.setBackgroundResource(typedArray.getResourceId(
R.styleable.Gallery_android_galleryItemBackground, 0));
iv.setPadding(0, 0, 0, 0);
} else {
iv = (ImageView) convertView;
}
iv.setImageResource(imageId[position]);
return iv;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return imageId.length;
}
};
Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.arg1 == 1) {
//--每隔timer时间间隔、执行一次gallery右移一张照片
gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
}
// 如果 gallery当前照片的下标 与 数组下标相同时、证明移动到了尾端
// 重新将gallery 设置为开始位置
if ((Integer) gallery.getSelectedItem() == imageId.length - 1) {
gallery.setSelection(0);//--设置照片未初始位置
}
};
};
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
Message msg = Message.obtain();
msg.arg1 = 1;
handler.sendMessage(msg);
}
};
}