Android摸索——高仿微博Tab界面

注:本文参考自农民伯伯的博客园,但在那基本之上又做了改善,原文链接http://www.cnblogs.com/over140/archive/2011/03/02/1968042.html#!comments

Tab页面效果是很多应用都会涉及到的,思路一般是tabwidget+radiobutton,而tab项的效果是将button设为null+文字+top图(selec实现)

反编译新浪微博4.0.1apk文件,研究其tab布局,做了个高仿品

首先是主布局文件:

将tabwidget隐藏,并用radiobutton取代,为单选按钮设置的style,其中最重要的是为其background设置了home_btn_bg.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" >
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingBottom="@dimen/toolbar_height" >
    </FrameLayout>
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" >
    </TabWidget>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="@dimen/toolbar_height"
        android:layout_gravity="bottom"
        android:gravity="center_vertical"
        android:orientation="horizontal" >
        <RadioGroup
            android:id="@+id/main_radio"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/toolbar_height"
            android:layout_gravity="bottom"
            android:gravity="center_vertical"
            android:orientation="horizontal" >
            <RadioButton
                android:id="@+id/radio_button0"
                style="@style/main_tab_bottom"
                android:checked="true"
                android:drawableTop="@drawable/weibo_home"
                android:text="@string/main_home"
            <RadioButton
                android:id="@+id/radio_button1"
                style="@style/main_tab_bottom"
                android:drawableTop="@drawable/weibo_message"
                android:text="@string/main_news" />
            <RadioButton
                android:id="@+id/radio_button2"
                style="@style/main_tab_bottom"
                android:drawableTop="@drawable/weibo_myinfo"
                android:text="@string/main_my_info" />
            <RadioButton
                android:id="@+id/radio_button3"
                style="@style/main_tab_bottom"
                android:drawableTop="@drawable/weibo_discover"
                android:text="@string/menu_search" />
            <RadioButton
                android:id="@+id/radio_button4"
                style="@style/main_tab_bottom"
                android:drawableTop="@drawable/weibo_more"
                android:text="@string/more" />
        </RadioGroup>
    </LinearLayout>
</TabHost>
button样式控制代码:

<style name="main_tab_bottom">
        <item name="android:textSize">@dimen/bottom_tab_font_size</item>
        <item name="android:textColor">@color/tab_text_color</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:background">@drawable/home_btn_bg</item>
        <item name="android:paddingTop">@dimen/bottom_tab_padding_up</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">@dimen/toolbar_height</item>
        <item name="android:button">@null</item>
        <item name="android:singleLine">true</item>
        <item name="android:drawablePadding">@dimen/bottom_tab_padding_drawable</item>
        <item name="android:layout_weight">1.0</item>
    </style>

为每个button top图设置其selector,实现选中前后不同效果。以第一个为例:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/tabbar_home_highlighted" android:state_checked="true" android:state_enabled="true"></item>
    <item android:drawable="@drawable/tabbar_home"></item>
</selector>

将tab上的文字也做类似处理:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="#FFFFFF"></item>
    <item android:color="#ff666666"></item>
</selector>

附上源码下载地址:

http://download.csdn.net/detail/zuse_ko/8147527

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt是一个跨平台的C++应用程序开发框架,它提供了丰富的GUI界面库和网络库等,非常适合开发聊天软件。在本文中,我们将介绍如何使用Qt实现一个高仿QQUI设计的聊天软件。 第一步:UI设计 QQUI是一种基于Qt的UI设计风格,它的特点是简洁、美观、易用。我们可以借鉴一下QQUI的设计思路,设计出我们的聊天软件UI。 首先,我们需要准备好UI所需的资源文件,包括图片、字体等。然后,在Qt Creator中创建一个新的“Qt Widgets Application”项目,选择“Dialog with Buttons Bottom”模板。在“Designer”中,我们可以使用“Widget Box”中的控件来设计UI界面,例如:Label、LineEdit、PushButton、TextBrowser等。我们可以使用样式表来设置控件的属性和样式,例如:颜色、字体、边框等。 第二步:网络通信 在聊天软件中,网络通信是必不可少的。我们可以使用Qt提供的网络库来实现客户端和服务器之间的通信。在本例中,我们将使用TCP协议来进行通信。 首先,我们需要在客户端中创建一个QTcpSocket对象,通过调用connectToHost()函数来连接服务器。连接成功后,我们可以使用write()函数向服务器发送数据,使用read()函数接收服务器发送的数据。当客户端需要关闭连接时,可以通过调用disconnectFromHost()函数来断开连接。 在服务器端,我们需要创建一个QTcpServer对象,通过调用listen()函数来监听客户端的连接请求。当客户端连接成功后,服务器会自动创建一个QTcpSocket对象与客户端进行通信。我们可以使用QTcpSocket对象的readyRead()信号来接收客户端发送的数据,使用write()函数向客户端发送数据。当服务器需要关闭连接时,可以通过调用close()函数来关闭连接。 第三步:消息处理 在聊天软件中,消息的处理非常重要。我们需要对接收到的消息进行解析,并根据消息类型来执行相应的操作。例如:当接收到一条文本消息时,需要在聊天窗口中显示该消息;当接收到一条图片消息时,需要在聊天窗口中显示该图片。 在本例中,我们将使用JSON格式来传递消息。每个消息都包含一个消息类型和消息内容。我们可以使用QJsonDocument和QJsonObject类来解析JSON格式的消息。 第四步:数据库存储 在聊天软件中,数据库存储可以帮助我们保存聊天记录、用户信息等。我们可以使用Qt提供的SQL库来实现数据库存储。 在本例中,我们将使用SQLite数据库来存储聊天记录。首先,我们需要在Qt Creator中创建一个新的SQLite数据库,并创建一个表来存储聊天记录。然后,我们可以使用QSqlDatabase类来连接数据库,使用QSqlQuery类来执行SQL语句。当接收到一条消息时,我们可以将消息内容存储到数据库中。 第五步:实现功能 在完成了以上四步之后,我们就可以开始实现聊天软件的各种功能了。例如:登录、注册、添加好友、发送消息等。 在本例中,我们将实现以下功能: 1. 登录和注册:用户需要输入用户名和密码进行登录或注册。 2. 添加好友:用户可以通过输入好友的用户名来添加好友。 3. 聊天窗口:用户可以选择好友进行聊天,发送和接收消息。 4. 聊天记录:聊天记录将保存在数据库中,用户可以查看历史聊天记录。 5. 用户信息:用户可以修改自己的用户名和密码。 第六步:优化和测试 在完成了功能的实现之后,我们需要对程序进行优化和测试。例如:优化界面的交互体验、提高程序的性能、进行功能测试和兼容性测试等。 最后,我们可以将程序打包成可执行文件,发布到用户手中。 总结 通过以上步骤,我们就可以使用Qt实现一个高仿QQUI设计的聊天软件了。Qt提供了丰富的GUI界面库和网络库等,可以帮助我们快速地开发跨平台的应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值