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

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

相关文章

C++对象布局及多态实现探索之内存布局(整理的很多链接)

本文通过观察对象的内存布局,跟踪函数调用的汇编代码。分析了C++对象内存的布局情况,虚函数的执行方式,以及虚继承,等等 文章链接:http://dev.yesky.com/254/2191254.shtml      论C/C++函数间动态内存的传递 (2005-07-30)   当你涉及到C/C++的核心编程的时候,你会无止境地与内存管理打交道。 文章链接:http://dev.yesky

通过SSH隧道实现通过远程服务器上外网

搭建隧道 autossh -M 0 -f -D 1080 -C -N user1@remotehost##验证隧道是否生效,查看1080端口是否启动netstat -tuln | grep 1080## 测试ssh 隧道是否生效curl -x socks5h://127.0.0.1:1080 -I http://www.github.com 将autossh 设置为服务,隧道开机启动

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测 目录 时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测基本介绍程序设计参考资料 基本介绍 MATLAB实现LSTM时间序列未来多步预测-递归预测。LSTM是一种含有LSTM区块(blocks)或其他的一种类神经网络,文献或其他资料中LSTM区块可能被描述成智能网络单元,因为

vue项目集成CanvasEditor实现Word在线编辑器

CanvasEditor实现Word在线编辑器 官网文档:https://hufe.club/canvas-editor-docs/guide/schema.html 源码地址:https://github.com/Hufe921/canvas-editor 前提声明: 由于CanvasEditor目前不支持vue、react 等框架开箱即用版,所以需要我们去Git下载源码,拿到其中两个主

Eclipse+ADT与Android Studio开发的区别

下文的EA指Eclipse+ADT,AS就是指Android Studio。 就编写界面布局来说AS可以边开发边预览(所见即所得,以及多个屏幕预览),这个优势比较大。AS运行时占的内存比EA的要小。AS创建项目时要创建gradle项目框架,so,创建项目时AS比较慢。android studio基于gradle构建项目,你无法同时集中管理和维护多个项目的源码,而eclipse ADT可以同时打开

android一键分享功能部分实现

为什么叫做部分实现呢,其实是我只实现一部分的分享。如新浪微博,那还有没去实现的是微信分享。还有一部分奇怪的问题:我QQ分享跟QQ空间的分享功能,我都没配置key那些都是原本集成就有的key也可以实现分享,谁清楚的麻烦详解下。 实现分享功能我们可以去www.mob.com这个网站集成。免费的,而且还有短信验证功能。等这分享研究完后就研究下短信验证功能。 开始实现步骤(新浪分享,以下是本人自己实现

基于Springboot + vue 的抗疫物质管理系统的设计与实现

目录 📚 前言 📑摘要 📑系统流程 📚 系统架构设计 📚 数据库设计 📚 系统功能的具体实现    💬 系统登录注册 系统登录 登录界面   用户添加  💬 抗疫列表展示模块     区域信息管理 添加物资详情 抗疫物资列表展示 抗疫物资申请 抗疫物资审核 ✒️ 源码实现 💖 源码获取 😁 联系方式 📚 前言 📑博客主页:

探索蓝牙协议的奥秘:用ESP32实现高质量蓝牙音频传输

蓝牙(Bluetooth)是一种短距离无线通信技术,广泛应用于各种电子设备之间的数据传输。自1994年由爱立信公司首次提出以来,蓝牙技术已经经历了多个版本的更新和改进。本文将详细介绍蓝牙协议,并通过一个具体的项目——使用ESP32实现蓝牙音频传输,来展示蓝牙协议的实际应用及其优点。 蓝牙协议概述 蓝牙协议栈 蓝牙协议栈是蓝牙技术的核心,定义了蓝牙设备之间如何进行通信。蓝牙协议

Python应用开发——30天学习Streamlit Python包进行APP的构建(9)

st.area_chart 显示区域图。 这是围绕 st.altair_chart 的语法糖。主要区别在于该命令使用数据自身的列和指数来计算图表的 Altair 规格。因此,在许多 "只需绘制此图 "的情况下,该命令更易于使用,但可定制性较差。 如果 st.area_chart 无法正确猜测数据规格,请尝试使用 st.altair_chart 指定所需的图表。 Function signa

python实现最简单循环神经网络(RNNs)

Recurrent Neural Networks(RNNs) 的模型: 上图中红色部分是输入向量。文本、单词、数据都是输入,在网络里都以向量的形式进行表示。 绿色部分是隐藏向量。是加工处理过程。 蓝色部分是输出向量。 python代码表示如下: rnn = RNN()y = rnn.step(x) # x为输入向量,y为输出向量 RNNs神经网络由神经元组成, python