zoukankan      html  css  js  c++  java
  • 几种tabhost的总结(2)

    底背景图标动画切换

    一。布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
    
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >
    
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="0.0dip"
                    android:layout_weight="1.0" >
                </FrameLayout>
    
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:visibility="gone" />
    
                <RelativeLayout
                    android:id="@+id/layout_bottom"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >
    
                    <RadioGroup
                        android:id="@+id/radiogroup"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom"
                        android:background="@drawable/bottombg"
                        android:gravity="center_vertical"
                        android:orientation="horizontal" >
    
                        <RadioButton
                            android:id="@+id/radio_news"
                            android:layout_width="wrap_content"
                            android:background="@drawable/tab_selector_news"
                            android:button="@null"
                            android:checked="true" />
    
                        <RadioButton
                            android:id="@+id/radio_topic"
                            android:layout_width="wrap_content"
                            android:background="@drawable/tab_selector_topic"
                            android:button="@null" />
    
                        <RadioButton
                            android:id="@+id/radio_pic"
                            android:layout_width="wrap_content"
                            android:background="@drawable/tab_selector_pic"
                            android:button="@null" />
    
                        <RadioButton
                            android:id="@+id/radio_follow"
                            android:layout_width="wrap_content"
                            android:background="@drawable/tab_selector_follow"
                            android:button="@null" />
    
                        <RadioButton
                            android:id="@+id/radio_vote"
                            android:layout_width="wrap_content"
                            android:background="@drawable/tab_selector_vote"
                            android:button="@null" />
                    </RadioGroup>
                </RelativeLayout>
            </LinearLayout>
        </TabHost>
    
    </LinearLayout>

    二。activity

    package com.ct.host;
    
    import android.app.TabActivity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.animation.TranslateAnimation;
    import android.widget.ImageView;
    import android.widget.RadioGroup;
    import android.widget.RadioGroup.OnCheckedChangeListener;
    import android.widget.RelativeLayout;
    import android.widget.TabHost;
    
    public class MainActivity extends TabActivity {
        /** Called when the activity is first created. */
        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) {
                // TODO Auto-generated method stub
                switch (checkedId) {
                case R.id.radio_news:
                    tabHost.setCurrentTabByTag("news");
    //                moveFrontBg(img, startLeft, 0, 0, 0);
                    moveFrontBg(img, startLeft, 0, 0, 0);
                    startLeft = 0;
                    break;
                case R.id.radio_topic:
                    tabHost.setCurrentTabByTag("topic");
                    moveFrontBg(img, startLeft, img.getWidth(), 0, 0);
                    startLeft = img.getWidth();
                    break;
                case R.id.radio_pic:
                    tabHost.setCurrentTabByTag("picture");
                    moveFrontBg(img, startLeft, img.getWidth() * 2, 0, 0);
                    startLeft = img.getWidth() * 2;
                    break;
                case R.id.radio_follow:
                    tabHost.setCurrentTabByTag("follow");
                    moveFrontBg(img, startLeft, img.getWidth() * 3, 0, 0);
                    startLeft = img.getWidth() * 3;
                    break;
                case R.id.radio_vote:
                    tabHost.setCurrentTabByTag("vote");
                    moveFrontBg(img, startLeft, img.getWidth() * 4, 0, 0);
                    startLeft = img.getWidth() * 4;
                    break;
    
                default:
                    break;
                }
            }
            
        };
        
        private void  moveFrontBg(View v, int startX, int toX, int startY, int toY){
            TranslateAnimation anim = new TranslateAnimation(startX, toX, startY, toY);
            anim.setDuration(200);
            anim.setFillAfter(true);
            v.setAnimation(anim);
            
        }
        
    }

    (在F:\java\MyTabHost2)

  • 相关阅读:
    ftp上传工具类&FTPClient通过代理连接到FTP服务器
    JS判断闰年与获取月份天数
    SpringBoot文件上传文件大小限制The field file exceeds its maximum permitted size of 1048576 bytes.
    JSON.parse解析json字符串包含 回车换行符报错
    JS解决加减乘除浮点类型丢失精度问题
    Mysql连接异常java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represents more than one time zone.
    Springboot基于Guava+自定义注解实现IP或自定义key限流 升级版
    Centos7设置默认进入图形界面和命令行界面
    第一节 RabbitMQ入门及安装
    第三节 Kafka性能优化实践
  • 原文地址:https://www.cnblogs.com/ct732003684/p/2849359.html
Copyright © 2011-2022 走看看