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);
                    }
                }
            }); 
  • 相关阅读:
    CF1329A Dreamoon Likes Coloring(贪心)
    CF1330B Dreamoon Likes Permutations
    AcWing338 计数问题(数位dp)
    AcWing311 月之谜(数位dp)
    AcWing310 启示录(数位dp)
    CF1332E Height All the Same(数学)
    CF1332D Walk on Matrix(构造)
    CF1332C K-Complete Word(思维)
    js作用域
    js原型链笔记
  • 原文地址:https://www.cnblogs.com/lovemo1314/p/4474465.html
Copyright © 2011-2022 走看看