Android新浪微博之主页面布局
来源:互联网 发布:纹理识别算法 编辑:程序博客网 时间:2024/05/29 17:43
授权成功后,会自动跳转到新浪微博的主页面。主界面由TabHost组成。布局代码和java代码如下:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <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="0.0dip" android:layout_weight="1.0" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" android:visibility="gone" /> <RadioGroup android:id="@+id/main_tab" android:layout_width="fill_parent" android:layout_height="45dp" android:layout_gravity="bottom" android:gravity="center_vertical" android:orientation="horizontal" > <RadioButton android:id="@+id/radiobtn_home" style="@style/main_tab_bottom" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_1_d" /> <RadioButton android:id="@+id/radiobtn_msg" style="@style/main_tab_bottom" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_2_d" /> <RadioButton android:id="@+id/radiobtn_user" style="@style/main_tab_bottom" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_3_d" /> </RadioGroup> </LinearLayout></TabHost>
WeoboMainActivity.java
package com.weibo.main;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.KeyEvent;import android.view.View;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.ImageView;import android.widget.RadioButton;import android.widget.TabHost;import android.widget.Toast;import android.app.Service;/** * @author SunnyMiao 2014-4-3下午5:40:53 * */@SuppressWarnings("deprecation")public class WeiboMainActivity extends TabActivity implementsOnCheckedChangeListener {private TabHost mytab;private Intent homeIntent; // 主页private Intent mesIntent; // 信息private Intent userIntent; // 个人资料private long ExitTime = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main_);Intent it = super.getIntent();this.mytab = this.getTabHost();this.homeIntent = new Intent(this, WeiboHomeActivity.class);this.mesIntent = new Intent(this, WeiboMsgActivity.class);this.userIntent = new Intent(this, WeiboUserActivity.class);initRadios();setupIntent();}// 初始化按钮private void initRadios() {// TODO Auto-generated method stub((RadioButton) findViewById(R.id.radiobtn_home)).setOnCheckedChangeListener(this);((RadioButton) findViewById(R.id.radiobtn_msg)).setOnCheckedChangeListener(this);((RadioButton) findViewById(R.id.radiobtn_user)).setOnCheckedChangeListener(this);}@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// TODO Auto-generated method stubif (isChecked) {switch (buttonView.getId()) {case R.id.radiobtn_home:this.mytab.setCurrentTabByTag("mblog_tab");break;case R.id.radiobtn_msg:this.mytab.setCurrentTabByTag("message_tab");break;case R.id.radiobtn_user:this.mytab.setCurrentTabByTag("userinfo_tab");break;}}}// 设置Intentprivate void setupIntent() {View imageView = new ImageView(getApplicationContext());imageView.setBackgroundResource(R.drawable.icon_1_d);View imageView2 = new ImageView(getApplicationContext());imageView2.setBackgroundResource(R.drawable.icon_2_d);View imageView3 = new ImageView(getApplicationContext());imageView3.setBackgroundResource(R.drawable.icon_3_d);mytab.addTab(mytab.newTabSpec("mblog_tab").setIndicator("mblog_tab").setContent(homeIntent));mytab.addTab(mytab.newTabSpec("message_tab").setIndicator("message_tab").setContent(mesIntent));mytab.addTab(mytab.newTabSpec("userinfo_tab").setIndicator("userinfo_tab").setContent(userIntent));}/** * 处理按下返回键的操作 */@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {switch (keyCode) {case KeyEvent.KEYCODE_BACK:// TODO Auto-generated catch blockif ((System.currentTimeMillis() - ExitTime) > 2000) {// 如果两次按键时间间隔大于2000毫秒,则不退出Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();ExitTime = System.currentTimeMillis();// 更新ExitTime} else {// back();break;// 否则退出程序}return true;}return super.onKeyDown(keyCode, event);}}
效果图为:
0 0
- Android新浪微博之主页面布局
- 微博主页面布局思路
- 新浪微博开发之微博主页的实现
- Android 微信主页面
- 主页面布局框架搭建
- 购物车布局主页面
- iOS 新浪微博客户端Demo实践之(三)微博主页
- (droid分享)新浪微博开发系列【五】之显示主页
- Android模仿新浪微博(主页微博,评论界面)
- Android 模仿微信主页面
- Android仿新浪微博底部布局TabHost
- 新浪微博底部布局
- Android 仿微信之(二)--主页面实现篇
- Android 仿微信之二--主页面实现篇
- Android 仿微信之(二)--主页面实现篇
- Android 仿微信之(二)--主页面实现篇
- Android之回退直接退出到主页面
- css3模仿新浪微博主页文字滚动
- 访问者模式的分析、结构图及基本代码
- 【git体验】git基础-3目录之间关系
- Angular JS解析(五)——显示文本
- ASP:Login控件(登录控件)
- o-1背包问题
- Android新浪微博之主页面布局
- 1059. Prime Factors (25)
- 使用PHP生成二维码
- 跟“大神”合作
- struts2上传文件
- iOS中Category类别(扩展类)专题总结
- ASP:CreateUserWizard控件(登录控件)
- Angular学习(六)——表单输入
- 分公司的分公司大夫敢死队分公司的风格豆腐干地方