zoukankan      html  css  js  c++  java
  • RadioButton 带下划线切换的案例

    xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        android:id="@+id/relOrder"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/White"
        xmlns:android="http://schemas.android.com/apk/res/android">
        
        <RadioGroup
            android:id="@+id/rgTabTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingBottom="@dimen/text_padding_small"
            android:paddingTop="@dimen/text_padding_small" >
    
            <RadioButton
                android:id="@+id/rbDoneOrder"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:checked="true"
                android:button="@null"
                android:gravity="center"
                android:padding="0dp"
                android:text="@string/order_done"
                android:textColor="@drawable/sel_tab_text_color"
                android:textSize="@dimen/content_text_size" />
            <RadioButton
                android:id="@+id/rbGoingOrder"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1.0"
                android:button="@null"
                android:gravity="center"
                android:padding="0dp"
                android:text="@string/order_going"
                android:textColor="@drawable/sel_tab_text_color"
                android:textSize="@dimen/content_text_size" />
        </RadioGroup>
        
        <LinearLayout
            android:id="@+id/indicatorLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/rgTabTitle"
            android:orientation="horizontal"
            android:weightSum="2" >
    
            <View
                android:id="@+id/indicatorView"
                android:layout_width="0dp"
                android:layout_height="@dimen/indicator_height"
                android:layout_weight="1.0"
                android:background="@color/bg_deep_color" />
        </LinearLayout>
        
        <View
            android:id="@+id/line1"
            android:layout_width="match_parent"
            android:layout_height="@dimen/divider_line_width"
            android:layout_below="@id/indicatorLayout"
            android:background="@color/divider_line_color" />
        
        <FrameLayout 
            android:id="@+id/frContractsHistory"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/line1"
            android:layout_marginTop="0dp"
            android:layout_marginRight="@dimen/outer_border_width"
            android:layout_marginLeft="@dimen/outer_border_width"
            android:background="@color/White" >
            
        </FrameLayout>
    
    </RelativeLayout>

    code:

    mIndicator = mRootView.findViewById(R.id.indicatorView);//underlne
    WindowManager wm = (WindowManager) context   //the the width of screen
                    .getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics outMetrics = new DisplayMetrics();
            wm.getDefaultDisplay().getMetrics(outMetrics);
    mIndicatorStepDistance  = outMetrics.widthPixels;
    
    mFm =getFragmentManager();
            FragmentTransaction mFragmentTrans =mFm.beginTransaction();
            mFragmentTrans.add(R.id.frContractsHistory, new OrderContractsLvFragment(R.layout.list_item_contract_done)).commit();
            mRgTabs.setOnCheckedChangeListener(new OnCheckedChangeListener(){
                @Override
                public void onCheckedChanged(RadioGroup container, int checkedId) {
                    FragmentTransaction mFragmentTrans =mFm.beginTransaction();
                    TranslateAnimation anim = null;
                    switch(checkedId){
                    case R.id.rbDoneOrder:
                        Toast.makeText(mContext, "done", Toast.LENGTH_LONG).show();
        mFragmentTrans.replace(R.id.frContractsHistory, 
                    new OrderContractsLvFragment(R.layout.list_item_contract_done));
            mFragmentTrans.commit();
                        anim = new TranslateAnimation(mIndicatorStepDistance * mIndicatorPosition, 0, 0, 0);
                        mIndicatorPosition = 0;
                        break;
                    case R.id.rbGoingOrder:
                        Toast.makeText(mContext, "going", Toast.LENGTH_LONG).show();
        mFragmentTrans.replace(R.id.frContractsHistory, 
                                new OrderContractsLvFragment(R.layout.list_item_contract_ongoing));
                        mFragmentTrans.commit();
                        
                        anim = new TranslateAnimation(mIndicatorStepDistance * mIndicatorPosition, mIndicatorStepDistance, 0, 0);
                        mIndicatorPosition = 1;
                        break;
                    }
                    if (anim != null) {
                        anim.setDuration(300);
                        anim.setFillAfter(true);
                        mIndicator.startAnimation(anim);
                    }
                }
            }); 
  • 相关阅读:
    win7 64位下 mongodb安装及命令运行
    CYQ.Data 快速开发EasyUI
    面试杂记:三个月的面试回忆录(携程、腾讯等)
    那点你不知道的XHtml(Xml+Html)语法知识(DTD、XSD)
    .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
    CYQ.Data 支持WPF相关的数据控件绑定(2013-08-09)
    CYQ.Data V4系列全面开源(2013-08-04)
    C#与Java对比学习:类型判断、类与接口继承、代码规范与编码习惯、常量定义
    C#与Java对比学习:数据类型、集合类、栈与队列、迭达、可变参数、枚举
    突破瓶颈,对比学习:Eclipse开发环境与VS开发环境的调试对比
  • 原文地址:https://www.cnblogs.com/lovemo1314/p/4474465.html
Copyright © 2011-2022 走看看