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
原创粉丝点击