• 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);
                    }
                }
            }); 
  • 相关阅读:
    时间转换(scanf的指定格式读入)
    RabbitMQ (五)主题(Topic)
    第01章 概述(1)
    bitmap与2-bitmap使用总结
    MyEclipse开启Jquery智能提示
    开启unity3D的学习之路
    《学习opencv》笔记——基本数据结构,CvMat,矩阵訪问
    使用squid架设自己的代理server
    Android KitKat 4.4平台开发-加入USB ADB和MTP功能支持
    Android:创建可穿戴应用
  • 原文地址:https://www.cnblogs.com/lovemo1314/p/4474465.html
Copyright © 2020-2023  润新知