首頁 收藏 QQ群
 網(wǎng)站導航

ZNDS智能電視網(wǎng) 推薦當貝市場

TV應用下載 / 資源分享區(qū)

軟件下載 | 游戲 | 討論 | 電視計算器

綜合交流 / 評測 / 活動區(qū)

交流區(qū) | 測硬件 | 網(wǎng)站活動 | Z幣中心

新手入門 / 進階 / 社區(qū)互助

新手 | 你問我答 | 免費刷機救磚 | ROM固件

查看: 14011|回復: 0
上一主題 下一主題
[案例]

項目實戰(zhàn)(新聞客戶端)步步為營

[復制鏈接]
跳轉到指定樓層
樓主
發(fā)表于 2013-8-28 16:27 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
9
                              
Main.xml
     
<?xml  <LinearLayout              <TabHost
  
                <LinearLayout
  
                    <FrameLayout
  
                    </FrameLayout>
  
              <TabWidget
  
                      <RelativeLayout
  
                        <RadioGroup
  
                                    <RadioButton
  
                                <RadioButton
  
                              <RadioButton
  
                              <RadioButton
  
                              <RadioButton
  
                        </RadioGroup>
  
            </RelativeLayout>
  
        </LinearLayout>
  
    </TabHost>
  
  </LinearLayout>
  
  package com.and.netease;
  
  import com.and.netease.utils.MoveBg;
  
import android.app.TabActivity;
  
import android.content.Intent;
  
import android.os.Bundle;
  
import android.widget.RadioGroup;
  
import android.widget.RadioGroup.OnCheckedChangeListener;
  
import android.widget.ImageView;
  
import android.widget.RelativeLayout;
  
import android.widget.TabHost;
  
  public class MainActivity extends TabActivity {
  
       TabHost tabHost;
  
       TabHost.TabSpec tabSpec;
  
       RadioGroup radioGroup;
  
       RelativeLayout  bOTTom_layout;
  
       ImageView img;
  
       int startLeft;
  
    @Override
  
    public void onCreate(Bundle  savedInstanceState) {
  
         super.onCreate(savedInstanceState);
  
         setContentView(R.layout.main);
  
        
  
        bottom_layout =  (RelativeLayout) findViewById(R.id.layout_bottom);
  
        
  
        tabHost = getTabHost();
  
         tabHost.addTab(tabHost.newTabSpec("news").setIndicator("News").setContent(new  Intent(this, TabNewsActivity.class)));
  
         tabHost.addTab(tabHost.newTabSpec("topic").setIndicator("Topic").setContent(new  Intent(this, TabTopicActivity.class)));
  
         tabHost.addTab(tabHost.newTabSpec("picture").setIndicator("Picture").setContent(new  Intent(this, TabPicActivity.class)));
  
         tabHost.addTab(tabHost.newTabSpec("follow").setIndicator("Follow").setContent(new  Intent(this, TabFollowActivity.class)));
  
         tabHost.addTab(tabHost.newTabSpec("vote").setIndicator("Vote").setContent(new  Intent(this, TabVoteActivity.class)));
  
        
  
        radioGroup =  (RadioGroup) findViewById(R.id.radiogroup);
  
         radioGroup.setOnCheckedChangeListener(checkedChangeListener);
  
        
  
        img = new  ImageView(this);
  
         img.setImageResource(R.drawable.tab_front_bg);
  
        bottom_layout.addView(img);
  
    }
  
   
  
       private  OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener()  {
  
                @Override
  
              public void  onCheckedChanged(RadioGroup group, int checkedId) {
  
                     switch  (checkedId) {
  
                     case  R.id.radio_news:
  
                            tabHost.setCurrentTabByTag("news");
  
//                         moveFrontBg(img,  startLeft, 0, 0, 0);
  
                            MoveBg.moveFrontBg(img,  startLeft, 0, 0, 0);
  
                            startLeft  = 0;
  
                            break;
  
                     case  R.id.radio_topic:
  
                            tabHost.setCurrentTabByTag("topic");
  
                            MoveBg.moveFrontBg(img,  startLeft, img.getWidth(), 0, 0);
  
                            startLeft  = img.getWidth();
  
                            break;
  
                     case  R.id.radio_pic:
  
                            tabHost.setCurrentTabByTag("picture");
  
                            MoveBg.moveFrontBg(img,  startLeft, img.getWidth() * 2, 0, 0);
  
                            startLeft  = img.getWidth() * 2;
  
                            break;
  
                     case  R.id.radio_follow:
  
                            tabHost.setCurrentTabByTag("follow");
  
                            MoveBg.moveFrontBg(img,  startLeft, img.getWidth() * 3, 0, 0);
  
                            startLeft  = img.getWidth() * 3;
  
                            break;
  
                     case  R.id.radio_vote:
  
                            tabHost.setCurrentTabByTag("vote");
  
                            MoveBg.moveFrontBg(img,  startLeft, img.getWidth() * 4, 0, 0);
  
                            startLeft  = img.getWidth() * 4;
  
                            break;
  
                       default:
  
                            break;
  
                     }
  
              }
  
       };
  
}
  
  package com.and.netease.utils;
  
  import android.view.View;
  
import  android.view.animation.TranslateAnimation;
  
  public class MoveBg {
  
         /**
  
          * 移動方法
  
          *
  
          * @param v
  
          *             需要移動的View
  
          * @param startX
  
          *             起始x坐標
  
          * @param toX
  
          *             終止x坐標
  
          * @param startY
  
          *             起始y坐標
  
          * @param toY
  
          *             終止y坐標
  
          */
  
         
  
         
  
         public  static void moveFrontBg(View view, int startX, int toX, int startY, int toY)  {
  
                   TranslateAnimation  anim = new TranslateAnimation(startX, toX, startY, toY);
  
                   anim.setDuration(200);
  
                   anim.setFillAfter(true);
  
                   view.startAnimation(anim);
  
         }
  
}
  
  <?xml  <LinearLayout              <RelativeLayout
  
                  <ImageView
  
                      <TextView
  
                        <ImageView
  
            </RelativeLayout>
  
      <RelativeLayout
  
                      <LinearLayout
  
                    <RelativeLayout
  
                          <TextView
  
                      </RelativeLayout>
  
              <RelativeLayout
  
                        <TextView
  
                      </RelativeLayout>
  
              <RelativeLayout
  
                        <TextView
  
                      </RelativeLayout>
  
              <RelativeLayout
  
                        <TextView
  
                      </RelativeLayout>
  
              <RelativeLayout
  
                        <TextView
  
                      </RelativeLayout>
  
              <RelativeLayout
  
                        <TextView
  
                      </RelativeLayout>
  
        </LinearLayout>
  
    </RelativeLayout>
  
  </LinearLayout>
  
  package com.and.netease;
  
  import com.and.netease.utils.MoveBg;
  
  import android.app.Activity;
  
import android.graphics.Color;
  
import android.os.Bundle;
  
import android.view.Gravity;
  
import android.view.View;
  
import android.view.View.OnClickListener;
  
import android.widget.RelativeLayout;
  
import android.widget.RelativeLayout.LayoutParams;
  
import android.widget.TextView;
  
  public class TabNewsActivity extends Activity {
  
       RelativeLayout layout;
  
       TextView tv_front;//需要移動的View
  
         TextView tv_bar_news;
  
       TextView tv_bar_sport;
  
       TextView tv_bar_play;
  
       TextView tv_bar_finance;
  
       TextView tv_bar_science;
  
       TextView tv_bar_more;
  
         int avg_width = 0;// 用于記錄平均每個標簽的寬度,移動的時候需要
  
         @Override
  
       protected void  onCreate(Bundle savedInstanceState) {
  
              super.onCreate(savedInstanceState);
  
              setContentView(R.layout.layout_news);
  
                initViews();
  
       }
  
         private void initViews()  {
  
              layout =  (RelativeLayout) findViewById(R.id.layout_title_bar);
  
                tv_bar_news =  (TextView) findViewById(R.id.tv_title_bar_news);
  
              tv_bar_sport =  (TextView) findViewById(R.id.tv_title_bar_sport);
  
              tv_bar_play =  (TextView) findViewById(R.id.tv_title_bar_play);
  
              tv_bar_finance =  (TextView) findViewById(R.id.tv_title_bar_finance);
  
              tv_bar_science =  (TextView) findViewById(R.id.tv_title_bar_science);
  
              tv_bar_more =  (TextView) findViewById(R.id.tv_title_bar_more);
  
                tv_bar_news.setOnClickListener(onClickListener);
  
              tv_bar_sport.setOnClickListener(onClickListener);
  
              tv_bar_play.setOnClickListener(onClickListener);
  
              tv_bar_finance.setOnClickListener(onClickListener);
  
              tv_bar_science.setOnClickListener(onClickListener);
  
              tv_bar_more.setOnClickListener(onClickListener);
  
                tv_front = new  TextView(this);
  
              tv_front.setBackgroundResource(R.drawable.slidebar);
  
              tv_front.setTextColor(Color.WHITE);
  
              tv_front.setText("頭條");
  
              tv_front.setGravity(Gravity.CENTER);
  
              RelativeLayout.LayoutParams  param = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT);
  
              param.addRule(RelativeLayout.CENTER_VERTICAL,  RelativeLayout.TRUE);
  
              layout.addView(tv_front,  param);
  
         }
  
         private OnClickListener  onClickListener = new OnClickListener() {
  
              int startX;//移動的起始位置
  
                @Override
  
              public void  onClick(View v) {
  
                     avg_width =  findViewById(R.id.layout).getWidth();
  
                     switch  (v.getId()) {
  
                     case  R.id.tv_title_bar_news:
  
                            MoveBg.moveFrontBg(tv_front,  startX, 0, 0, 0);
  
                            startX  = 0;
  
                            tv_front.setText(R.string.title_news_category_tops);
  
                            break;
  
                     case  R.id.tv_title_bar_sport:
  
                            MoveBg.moveFrontBg(tv_front,  startX, avg_width, 0, 0);
  
                            startX  = avg_width;
  
                            tv_front.setText(R.string.title_news_category_sport);
  
                            break;
  
                     case  R.id.tv_title_bar_play:
  
                            MoveBg.moveFrontBg(tv_front,  startX, avg_width * 2, 0, 0);
  
                            startX  = avg_width * 2;
  
                            tv_front.setText(R.string.title_news_category_play);
  
                            break;
  
                     case  R.id.tv_title_bar_finance:
  
                            MoveBg.moveFrontBg(tv_front,  startX, avg_width * 3, 0, 0);
  
                            startX  = avg_width * 3;
  
                            tv_front.setText(R.string.title_news_category_finance);
  
                            break;
  
                     case  R.id.tv_title_bar_science:
  
                            MoveBg.moveFrontBg(tv_front,  startX, avg_width * 4, 0, 0);
  
                            startX  = avg_width * 4;
  
                            tv_front.setText(R.string.title_news_category_science);
  
                            break;
  
                     case  R.id.tv_title_bar_more:
  
                            MoveBg.moveFrontBg(tv_front,  startX, avg_width * 5, 0, 0);
  
                            startX  = avg_width * 5;
  
                            tv_front.setText(R.string.title_news_category_more);
  
                            break;
  
                       default:
  
                            break;
  
                     }
  
                }
  
       };
  
  }
  
tabActivity的功能。這里不再贅述。
layout_topic.xml)
     
<?xml  <LinearLayout              <RelativeLayout
  
                  <ImageView
  
                      <TextView
  
                  </RelativeLayout>
  
  </LinearLayout>
  
  package com.and.netease;
  
  import android.app.Activity;
  
import android.os.Bundle;
  
  public class TabTopicActivity extends Activity {
  
         @Override
  
       protected void  onCreate(Bundle savedInstanceState) {
  
              // TODO  Auto-generated method stub
  
              super.onCreate(savedInstanceState);
  
              setContentView(R.layout.layout_topic);
  
       }
  
}
   </div

上一篇:第三十五講:App Widget入門指南
下一篇:andriod 和GPS整合實例
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

Archiver|新帖|標簽|軟件|Sitemap|ZNDS智能電視網(wǎng) ( 蘇ICP備2023012627號 )

網(wǎng)絡信息服務信用承諾書 | 增值電信業(yè)務經(jīng)營許可證:蘇B2-20221768 丨 蘇公網(wǎng)安備 32011402011373號

GMT+8, 2024-10-19 20:36 , Processed in 0.079273 second(s), 13 queries , Redis On.

Powered by Discuz!

監(jiān)督舉報:report#znds.com (請將#替換為@)

© 2007-2024 ZNDS.Com

快速回復 返回頂部 返回列表