• 开源中国客户端源码阅读笔记


    1、
    <include layout="@layout/main_header" />   
        
        <net.oschina.app.widget.ScrollLayout   
          android:id="@+id/main_scrolllayout"    
          android:layout_width="fill_parent"    
          android:layout_height="fill_parent"
             android:layout_weight="1">    
      
           <include layout="@layout/frame_news" />
          
          <include layout="@layout/frame_question" />
          
          <include layout="@layout/frame_tweet" />
              
          <include layout="@layout/frame_active/>
           
        </net.oschina.app.widget.ScrollLayout> 
        
        <include layout="@layout/main_footer" />   
    通过include其他的layout拆分了设计
    是如何在自定义控件里又包含了其他的layout?
    android:layout_weight="1" 的作用是指定控件所占空间的权重,默认为0,即为怎么设定怎么显示
        而设为1说明是平摊控件,这样两个android:layout_width="fill_parent" 的控件会左右各占一半空间
     
    2.
    <Button 
                 android:id="@+id/frame_btn_news_lastest"
                 style="@style/frame_button"
                 android:text="@string/frame_title_news_lastest"/>
     
    <style name="frame_button">
            <item name="android:layout_width">fill_parent</item>
               <item name="android:layout_height">fill_parent</item>
               <item name="android:layout_weight">1</item>
               <item name="android:background">@drawable/frame_button_bg</item>
               <item name="android:textColor">@color/frame_button_text_light</item>
        </style>
     
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_enabled="true" android:drawable="@drawable/frame_button_n" />
        <item android:state_enabled="false" android:drawable="@drawable/frame_button_p" />
    </selector>
     
    <selector
      xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_enabled="true" android:color="@color/frame_button_text_nor" />
        <item android:state_enabled="false" android:color="@color/frame_button_text_select" />
        <item android:color="@color/frame_button_text_nor" />
    </selector>
    对用一些多次重用的属性(比如在一组按钮中),可以设为一个style供调用style="@style/frame_button"
    按钮的背景可以设置为一个selector,使其在不同的状态下有不同的图像,文字的颜色也可以这样
     
    3.
    <ImageView android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="@drawable/frame_button_cutline"/>
    仿TAB按钮之间的分隔效果是通过贴图实现的
     
    4,
    工具栏的TAB效果是用按钮模拟出来的(这里用RadioButton不知道有何深意,但是却没用RadioButtonGroup)
    通过数组来操作,统一操作
     
    /**
         * 初始化水平滚动翻页
         */
        private void initPageScroll()
        {
            mScrollLayout = (ScrollLayout) findViewById(R.id.main_scrolllayout);
            
            LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main_linearlayout_footer);
            mHeadTitles = getResources().getStringArray(R.array.head_titles);
            mViewCount = mScrollLayout.getChildCount();
            mButtons = new RadioButton[mViewCount];
            
            for(int i = 0; i < mViewCount; i++)
            {
                mButtons[i] = (RadioButton) linearLayout.getChildAt(i*2); 
    获取底部工具栏的单选按钮,存入数组中,所以通过private RadioButton fbNews一直无法找到处理操作的函数)
                mButtons[i].setTag(i);
                mButtons[i].setChecked(false);
                mButtons[i].setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        int pos = (Integer)(v.getTag());
                        //点击当前项刷新
                        if(mCurSel == pos) {
                            switch (pos) {
                            case 0://资讯+博客
                                if(lvNews.getVisibility() == View.VISIBLE)
                                    lvNews.clickRefresh();
                                else
                                    lvBlog.clickRefresh();
                                break;    
                            case 1://问答
                                lvQuestion.clickRefresh();
                                break;
                            case 2://动弹
                                lvTweet.clickRefresh();
                                break;
                            case 3://动态+留言
                                if(lvActive.getVisibility() == View.VISIBLE)
                                    lvActive.clickRefresh();
                                else
                                    lvMsg.clickRefresh();
                                break;
                            }
                        }
                        mScrollLayout.snapToScreen(pos);
                    }
                });
            }
            
            //设置第一显示屏
            mCurSel = 0;
            mButtons[mCurSel].setChecked(true);
            
            mScrollLayout.SetOnViewChangeListener(new ScrollLayout.OnViewChangeListener() {
                public void OnViewChange(int viewIndex) {
                    //切换列表视图-如果列表数据为空:加载数据
                    switch (viewIndex) {
                    case 0://资讯
                        if(lvNews.getVisibility() == View.VISIBLE) {
                            if(lvNewsData.isEmpty()) {
                                loadLvNewsData(curNewsCatalog, 0, lvNewsHandler, UIHelper.LISTVIEW_ACTION_INIT);
                            }
                        } else {
                            if(lvBlogData.isEmpty()) {
                                loadLvBlogData(curNewsCatalog, 0, lvBlogHandler, UIHelper.LISTVIEW_ACTION_INIT);
                            }
                        }
                        break;    
                    case 1://问答
                        if(lvQuestionData.isEmpty()) {
                            loadLvQuestionData(curQuestionCatalog, 0, lvQuestionHandler, UIHelper.LISTVIEW_ACTION_INIT);
                        } 
                        break;
                    case 2://动弹
                        if(lvTweetData.isEmpty()) {
                            loadLvTweetData(curTweetCatalog, 0, lvTweetHandler, UIHelper.LISTVIEW_ACTION_INIT);
                        }
                        break;
                    case 3://动态
                        //判断登录
                        if(!appContext.isLogin()){
                            if(lvActive.getVisibility()==View.VISIBLE && lvActiveData.isEmpty()){
                                lvActive_foot_more.setText(R.string.load_empty);
                                lvActive_foot_progress.setVisibility(View.GONE);
                            }else if(lvMsg.getVisibility()==View.VISIBLE && lvMsgData.isEmpty()){
                                lvMsg_foot_more.setText(R.string.load_empty);
                                lvMsg_foot_progress.setVisibility(View.GONE);
                            }
                            UIHelper.showLoginDialog(Main.this);
                            break;
                        }
                        //处理通知信息
                        if(bv_atme.isShown()) 
                            frameActiveBtnOnClick(framebtn_Active_atme, ActiveList.CATALOG_ATME, UIHelper.LISTVIEW_ACTION_REFRESH);
                        else if(bv_review.isShown()) 
                            frameActiveBtnOnClick(framebtn_Active_comment, ActiveList.CATALOG_COMMENT, UIHelper.LISTVIEW_ACTION_REFRESH);
                        else if(bv_message.isShown())
                            frameActiveBtnOnClick(framebtn_Active_message, 0, UIHelper.LISTVIEW_ACTION_REFRESH);
                        else if(lvActive.getVisibility() == View.VISIBLE && lvActiveData.isEmpty())
                            loadLvActiveData(curActiveCatalog, 0, lvActiveHandler, UIHelper.LISTVIEW_ACTION_INIT);
                        else if(lvMsg.getVisibility() == View.VISIBLE && lvMsgData.isEmpty())
                            loadLvMsgData(0, lvMsgHandler, UIHelper.LISTVIEW_ACTION_INIT);
                        break;
                    }
                    setCurPoint(viewIndex);
                }
            });
        }
        /**
         * 设置底部栏当前焦点
         * @param index
         */
        private void setCurPoint(int index)
        {
            if (index < 0 || index > mViewCount - 1 || mCurSel == index)
                return;
           
            mButtons[mCurSel].setChecked(false);
            mButtons[index].setChecked(true);        
            mHeadTitle.setText(mHeadTitles[index]);        
            mCurSel = index;
            
            mHead_search.setVisibility(View.GONE);
            mHeadPub_post.setVisibility(View.GONE);
            mHeadPub_tweet.setVisibility(View.GONE);
            //头部logo、发帖、发动弹按钮显示
            if(index == 0){
                mHeadLogo.setImageResource(R.drawable.frame_logo_news);
                mHead_search.setVisibility(View.VISIBLE);
            }
            else if(index == 1){
                mHeadLogo.setImageResource(R.drawable.frame_logo_post);
                mHeadPub_post.setVisibility(View.VISIBLE);
            }
            else if(index == 2){
                mHeadLogo.setImageResource(R.drawable.frame_logo_tweet);
                mHeadPub_tweet.setVisibility(View.VISIBLE);
            }
            else if(index == 3){
                mHeadLogo.setImageResource(R.drawable.frame_logo_active);
                mHeadPub_tweet.setVisibility(View.VISIBLE);
            }
        }
     




  • 相关阅读:
    常见算法的时间复杂度
    electron 展示pdf
    AudioContext
    js 计算文字宽度
    python 窗口被关闭报错
    qq行情数据。sina行情JOSN,建议用qq,涨跌,财务数据有-市盈
    python AttributeError: 'NoneType' object has no attribute 'prepare'
    策略日志
    使用Python下载A股行情的几种方法
    easytrader
  • 原文地址:https://www.cnblogs.com/mushan/p/3347725.html
Copyright © 2020-2023  润新知