Androidテンセントマイクロブログクライアント開発一:下にあるTabの実現

12010 ワード

Android腾讯微博客户端开发一:在下方的Tab的实现     Android腾讯微博客户端开发一:在下方的Tab的实现
赤いのはres下drawableフォルダの下のselectorファイルで、内容はselectorファイルコードです.
<?xml version="1.0" encoding="UTF-8"?>

 

<selector

 

  xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]">

 

    <item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_normal" /></span> 

    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_active" /></span> 

    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_normal" /></span>

    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_active" /></span>

    <item android:state_pressed="true" android:drawable=<span style="background-color: #00ff00;">"@drawable/tab_timeline_normal" /></span>

 

</selector>


あなたが押したときや、時間通りに待たないなどの効果的な変更もあり、具体的にはselectorに関する知識を参照することができます.緑は2枚の異なる効果の画像です
Mainactivityコード
public class MainActivity extends TabActivity {

 



        private TabHost tabHost;

        private RadioGroup mainbtGroup;

        private static final String HOME = "  ";

        private static final String REFER = "  ";

        private static final String SECRET = "  ";

        private static final String SEARCH = "  ";

        private static final String ATTENTIION = "  ";

 

            @Override

         public void onCreate(Bundle savedInstanceState) {

 



                super.onCreate(savedInstanceState); 

                setContentView(R.layout.tabhost);



               tabHost = this.getTabHost();

 

              View view1 = View.inflate(MainActivity.this, R.layout.tab, null);

 

                ((ImageView) view1.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_timeline_selector)</span>;

 

                ((TextView) view1.findViewById(R.id.tab_textview_title)).setText(HOME);

            TabHost.TabSpec spec1 = tabHost.newTabSpec(HOME)

 

                                .setIndicator(view1)

                                 .setContent(new Intent(this, HomeTimeLineActivity.class));

 

                tabHost.addTab(spec1);

                

                View view2 = View.inflate(MainActivity.this, R.layout.tab, null);

                 ((ImageView) view2.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_atme_selector)</span>;

                ((TextView) view2.findViewById(R.id.tab_textview_title)).setText(REFER);

 

                TabHost.TabSpec spec2 = tabHost.newTabSpec(REFER)

 



                                .setIndicator(view2)

                                 .setContent(new Intent(this, ReferActivity.class));

 

                tabHost.addTab(spec2);

                 

                View view3 = View.inflate(MainActivity.this, R.layout.tab, null);

                ((ImageView) view3.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_message_selector)</span>;

 



                ((TextView) view3.findViewById(R.id.tab_textview_title)).setText(SECRET);

             TabHost.TabSpec spec3 = tabHost.newTabSpec(SECRET)

 

                               .setIndicator(view3)

                               .setContent(new Intent(this, MessageActivity.class));

 

                tabHost.addTab(spec3);

                 

                View view4 = View.inflate(MainActivity.this, R.layout.tab, null);

                ((ImageView) view4.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_explore_selector</span>);

 

                ((TextView) view4.findViewById(R.id.tab_textview_title)).setText(SEARCH);

 

              TabHost.TabSpec spec4 = tabHost.newTabSpec(SEARCH)

                               .setIndicator(view4)

                               .setContent(new Intent(this, SearchActivity.class));

 

                tabHost.addTab(spec4);

                 

                View view5 = View.inflate(MainActivity.this, R.layout.tab, null);

 

                ((ImageView) view5.findViewById(R.id.tab_imageview_icon)).setImageResource(<span style="background-color: #ff0000;">R.drawable.tab_focus_selector</span>);

                 ((TextView) view5.findViewById(R.id.tab_textview_title)).setText(ATTENTIION);

 

             TabHost.TabSpec spec5 = tabHost.newTabSpec(ATTENTIION) 

                                .setIndicator(view5)

                               .setContent(new Intent(this, AttentionActivity.class));

                 tabHost.addTab(spec5);

         }

 

は1枚.png形式の画像、これは役に立ちますよandroidでは、画像のリフトの問題を処理するのによく使われています.左と上の小さな点は伸ばすところを表し、右と下の点は内容領域を表します..9について.pngフォーマットの画像はandroidの中でもっと多くの応用を見なければなりませんここ
Tabhostレイアウトファイルコード
<?xml version="1.0" encoding="UTF-8"?>

 

<TabHost android:id="@android:id/tabhost"  
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]"> <RelativeLayout 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="fill_parent" /> <TabWidget android:id="@android:id/tabs" <span style="background-color: #ff0000;">
              android:background="@drawable/tab_bkg"</span> android:fadingEdge="none" android:fadingEdgeLength="0.0px" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> </RelativeLayout> </TabHost>

Tabhostレイアウトファイルコード
android:layout_alignParentBottom="true"  tab             , android  RelativeLayout   

 

Tabレイアウトファイルは、あなたが見た5つのボタンのレイアウトファイルコードです.
<?xml version="1.0" encoding="UTF-8"?>

 

<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"

 

  xmlns:android="[url=http://schemas.android.com/apk/res/android]http://schemas.android.com/apk/res/android[/url]">

 

    <ImageView android:id="@+id/tab_imageview_icon" android:layout_width="fill_parent" android:layout_height="32.0dip" android:scaleType="fitCenter" />

 

    <TextView android:id="@+id/tab_textview_title" android:textSize="11.0sp"  android:ellipsize="marquee" android:gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:marqueeRepeatLimit="1" />

 

</LinearLayout>