新浪微博开发之主程序界面的实现

2023-11-20 15:48

本文主要是介绍新浪微博开发之主程序界面的实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

授权用户登录后进入到程序主界面,主界面包括顶部标题栏、中间微博内容栏和底部菜单栏。顶部标题栏又包括发微博按钮、标题、和刷新按钮,而中间内容栏为ListView,底部菜单栏是使用RadioGroup实现的,关于底部菜单栏的实现可参考这边文章:新浪微博布局学习——妙用TabHost写的很好,这里就不做过多的解释了!

主界面效果图:

主界面布局代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:background="@android:color/white"android:layout_height="fill_parent"><include android:id="@+id/home_title" layout="@layout/title" /><TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent"android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"><LinearLayout android:orientation="vertical"android:layout_width="fill_parent" android:layout_height="fill_parent"><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:visibility="gone" android:layout_width="fill_parent"android:layout_height="wrap_content" android:layout_weight="0.0" /><RadioGroup android:gravity="center_vertical"android:layout_gravity="bottom" android:orientation="horizontal"android:id="@+id/main_radio" android:background="@drawable/bg_title"android:layout_width="fill_parent" android:layout_height="wrap_content"><RadioButton android:text="@string/main_home"android:checked="true" android:id="@+id/radio_button0"android:drawableTop="@drawable/icon_home"style="@style/main_tab_bottom" /><RadioButton android:id="@+id/radio_button1"android:text="@string/main_news"android:drawableTop="@drawable/icon_meassage" style="@style/main_tab_bottom" /><RadioButton android:id="@+id/radio_button2"android:text="@string/main_my_info"android:drawableTop="@drawable/icon_selfinfo" style="@style/main_tab_bottom" /><RadioButton android:id="@+id/radio_button3"android:text="@string/main_square"android:drawableTop="@drawable/icon_square" style="@style/main_tab_bottom" /><RadioButton android:id="@+id/radio_button4"android:text="@string/main_more"android:drawableTop="@drawable/icon_more" style="@style/main_tab_bottom" /></RadioGroup></LinearLayout></TabHost>
</LinearLayout>
主界面代码如下:

package com.cloay.weibo.ui;import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.TextView;import com.cloay.weibo.R;
import com.cloay.weibo.service.MainService;
/*** 使用TabActivity实现主界面* @author Cloay* 2012-2-24* 下午04:26:07*/
public class MainActivity extends TabActivity implements OnCheckedChangeListener  {private ImageButton updateStatus;private ImageButton refresh;private TabHost tabHost;private Intent homeIntent;  //主页private Intent mesIntent;   //信息private Intent infoIntent;  //个人资料private Intent squareIntent;  //广场private Intent moreIntent;    //更多private TextView title;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);   //去掉系统标题栏MainService.allActivity.add(this);setContentView(R.layout.main);this.tabHost = this.getTabHost();initData();    //初始化数据initBtnListener();//为各个按钮设置监听器setTab();//增加Tab项}/*** 增加Tab项*/private void setTab() {tabHost.addTab(tabHost.newTabSpec("C_HOME").setIndicator("C_HOME").setContent(homeIntent));tabHost.addTab(tabHost.newTabSpec("C_MES").setIndicator("C_MES").setContent(mesIntent));tabHost.addTab(tabHost.newTabSpec("C_INFO").setIndicator("C_INFO").setContent(infoIntent));tabHost.addTab(tabHost.newTabSpec("C_SQUARE").setIndicator("C_SQUARE").setContent(squareIntent));tabHost.addTab(tabHost.newTabSpec("C_MORE").setIndicator("C_MORE").setContent(moreIntent));}/*** 为底部按钮设置监听器*/private void initBtnListener() {((RadioButton)findViewById(R.id.radio_button0)).setOnCheckedChangeListener(this);((RadioButton)findViewById(R.id.radio_button1)).setOnCheckedChangeListener(this);((RadioButton)findViewById(R.id.radio_button2)).setOnCheckedChangeListener(this);((RadioButton)findViewById(R.id.radio_button3)).setOnCheckedChangeListener(this);((RadioButton)findViewById(R.id.radio_button4)).setOnCheckedChangeListener(this);}/*** 设置各个intent*/private void initData() {title = (TextView) findViewById(R.id.title_text);updateStatus = (ImageButton) findViewById(R.id.title_bt_left);updateStatus.setOnClickListener(new OnClickListener() { //打开发微博界面@Overridepublic void onClick(View v) {Intent intent = new Intent(MainActivity.this, UpdateStatus.class);startActivity(intent);}});refresh = (ImageButton) findViewById(R.id.title_bt_right);  //refresh.setOnClickListener(new OnClickListener() {  //刷新按钮监听事件//获取当前HomeActivity,调用refresh()方法 刷新数据@Overridepublic void onClick(View v) {HomeActivity home = (HomeActivity) getCurrentActivity();   home.refresh();   }});homeIntent = new Intent(this, HomeActivity.class);mesIntent = new Intent(this, MesActivity.class);infoIntent = new Intent(this, InfoActivity.class);squareIntent = new Intent(this, SquareActivity.class);moreIntent = new Intent(this, MoreActivity.class);}@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(isChecked){switch(buttonView.getId()){case R.id.radio_button0:this.tabHost.setCurrentTabByTag("C_HOME");  //跳转到首页title.setText("微博主页");refresh.setVisibility(View.VISIBLE);break;case R.id.radio_button1:this.tabHost.setCurrentTabByTag("C_MES");   //跳转到消息页title.setText("消息提醒");refresh.setVisibility(View.GONE);break;case R.id.radio_button2:refresh.setVisibility(View.GONE);title.setText("个人资料");this.tabHost.setCurrentTabByTag("C_INFO");   //个人资料break;case R.id.radio_button3:refresh.setVisibility(View.GONE);title.setText("微博广场");this.tabHost.setCurrentTabByTag("C_SQUARE");  //微博广场break;case R.id.radio_button4:refresh.setVisibility(View.GONE);title.setText("更多");this.tabHost.setCurrentTabByTag("C_MORE");	  //更多菜单break;}}}@Overridepublic boolean dispatchKeyEvent(KeyEvent event) {if((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && (event.getAction() == KeyEvent.ACTION_DOWN)){// 弹出退出提示对话框MainService.showExitDlg(MainActivity.this);
//			System.out.println("=======> dispatchKeyEvent");return true;}return super.dispatchKeyEvent(event);}
}

该注释的地方我都详细注释了,这里就不过多作解释了!下一篇我们将学习微博的获取!

有什么问题及建议请留言,大家一起交流学习!

说明:转载请注明出处!

这篇关于新浪微博开发之主程序界面的实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/395710

相关文章

Java实现视频格式转换的完整指南

《Java实现视频格式转换的完整指南》在Java中实现视频格式的转换,通常需要借助第三方工具或库,因为视频的编解码操作复杂且性能需求较高,以下是实现视频格式转换的常用方法和步骤,需要的朋友可以参考下... 目录核心思路方法一:通过调用 FFmpeg 命令步骤示例代码说明优点方法二:使用 Jaffree(FF

基于C#实现MQTT通信实战

《基于C#实现MQTT通信实战》MQTT消息队列遥测传输,在物联网领域应用的很广泛,它是基于Publish/Subscribe模式,具有简单易用,支持QoS,传输效率高的特点,下面我们就来看看C#实现... 目录1、连接主机2、订阅消息3、发布消息MQTT(Message Queueing Telemetr

Java实现图片淡入淡出效果

《Java实现图片淡入淡出效果》在现代图形用户界面和游戏开发中,**图片淡入淡出(FadeIn/Out)**是一种常见且实用的视觉过渡效果,它可以用于启动画面、场景切换、轮播图、提示框弹出等场景,通过... 目录1. 项目背景详细介绍2. 项目需求详细介绍2.1 功能需求2.2 非功能需求3. 相关技术详细

Python实现获取带合并单元格的表格数据

《Python实现获取带合并单元格的表格数据》由于在日常运维中经常出现一些合并单元格的表格,如果要获取数据比较麻烦,所以本文我们就来聊聊如何使用Python实现获取带合并单元格的表格数据吧... 由于在日常运维中经常出现一些合并单元格的表格,如果要获取数据比较麻烦,现将将封装成类,并通过调用list_exc

使用animation.css库快速实现CSS3旋转动画效果

《使用animation.css库快速实现CSS3旋转动画效果》随着Web技术的不断发展,动画效果已经成为了网页设计中不可或缺的一部分,本文将深入探讨animation.css的工作原理,如何使用以及... 目录1. css3动画技术简介2. animation.css库介绍2.1 animation.cs

Java进行日期解析与格式化的实现代码

《Java进行日期解析与格式化的实现代码》使用Java搭配ApacheCommonsLang3和Natty库,可以实现灵活高效的日期解析与格式化,本文将通过相关示例为大家讲讲具体的实践操作,需要的可以... 目录一、背景二、依赖介绍1. Apache Commons Lang32. Natty三、核心实现代

SpringBoot实现接口数据加解密的三种实战方案

《SpringBoot实现接口数据加解密的三种实战方案》在金融支付、用户隐私信息传输等场景中,接口数据若以明文传输,极易被中间人攻击窃取,SpringBoot提供了多种优雅的加解密实现方案,本文将从原... 目录一、为什么需要接口数据加解密?二、核心加解密算法选择1. 对称加密(AES)2. 非对称加密(R

基于Go语言实现Base62编码的三种方式以及对比分析

《基于Go语言实现Base62编码的三种方式以及对比分析》Base62编码是一种在字符编码中使用62个字符的编码方式,在计算机科学中,,Go语言是一种静态类型、编译型语言,它由Google开发并开源,... 目录一、标准库现状与解决方案1. 标准库对比表2. 解决方案完整实现代码(含边界处理)二、关键实现细

python通过curl实现访问deepseek的API

《python通过curl实现访问deepseek的API》这篇文章主要为大家详细介绍了python如何通过curl实现访问deepseek的API,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编... API申请和充值下面是deepeek的API网站https://platform.deepsee

SpringBoot实现二维码生成的详细步骤与完整代码

《SpringBoot实现二维码生成的详细步骤与完整代码》如今,二维码的应用场景非常广泛,从支付到信息分享,二维码都扮演着重要角色,SpringBoot是一个非常流行的Java基于Spring框架的微... 目录一、环境搭建二、创建 Spring Boot 项目三、引入二维码生成依赖四、编写二维码生成代码五