快速迭代用
布局
RadioButton --->rb_for_orders.xml
RadioButton -->背景bg_radio_forum.xml
RadioButton -->下划线line_bottom_with_blue_bold_for_forum.xml
SmartTabLayout
http://www.jcodecraeer.com/a/opensource/2015/0331/2674.html
http://blog.csdn.net/lmj623565791/article/details/42160391
import java.util.ArrayList; import org.json.JSONObject; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.HorizontalScrollView; import android.widget.RadioButton; import android.widget.RadioGroup; import com.android.volley.Response.Listener; import com.yirui.youbao.App; import com.yirui.youbao.fragment.OrderListFragment; import com.yirui.youbao.model.KeyValue; import com.yirui.youbao.net.Commands; /** * 订单管理 * @author pythoner * */ public class OrdersActivity extends BaseActivity implements View.OnClickListener { private Context context; private HorizontalScrollView hScrollView; private RadioGroup radioGroup; private ArrayList<KeyValue> tabs = new ArrayList<KeyValue>(); private ViewPager viewPager; private FragmentPagerAdapter pagerAdapter; private Fragment[] fragments; private int curPosition=0; private KeyValue curKeyValue=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_orders); context = this; initActionBar("", App.res.getDrawable(R.drawable.back), "订单管理", "创建订单",null); initViews(); } @Override public void doRightButtonClick(View v) { Commands.doCommandOrderCreate(context, App.user,null,new Listener<JSONObject>() { @Override public void onResponse(JSONObject response){ // TODO Auto-generated method stub // Log.i("tag", response.toString()); if (isSuccess(response)) { showToast("创建订单成功"); } } }); } private void initViews() { //1:未确认;2:待支付;3:已支付;4:已使用;5;用户退订;6:停车场退订;7:退款中;8;已退款 tabs.add(new KeyValue("1","待确认")); tabs.add(new KeyValue("2","待支付")); tabs.add(new KeyValue("3","已支付")); tabs.add(new KeyValue("4","已使用")); tabs.add(new KeyValue("5","用户退订")); tabs.add(new KeyValue("6","停车场退订")); tabs.add(new KeyValue("7","退款中")); tabs.add(new KeyValue("8","已退款")); initIndicator(); initViewPager(); } private void initIndicator(){ hScrollView = (HorizontalScrollView) findViewById(R.id.hScrollView); radioGroup = (RadioGroup) findViewById(R.id.radioGroup); for (int i = 0; i < tabs.size(); i++){ KeyValue tag = tabs.get(i); RadioButton child = (RadioButton) LayoutInflater.from(context).inflate(R.layout.rb_for_orders, null); child.setId(i); child.setTag(tag); child.setText(tag.getSecond()); child.setBackgroundResource(R.drawable.bg_radio_forum); child.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ // TODO Auto-generated method stub int id = v.getId(); viewPager.setCurrentItem(id); curPosition=id; curKeyValue = (KeyValue) v.getTag(); } }); if(i==curPosition){ child.setChecked(true); } radioGroup.addView(child); } } private void initViewPager(){ fragments = new Fragment[tabs.size()]; for(int i=0;i<tabs.size();i++){ fragments[i] = OrderListFragment.newInstance(tabs.get(i)); } pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public int getCount() { return fragments.length; } @Override public Fragment getItem(int position) { return fragments[position]; } }; viewPager = (ViewPager) findViewById(R.id.viewPager); viewPager.setOffscreenPageLimit(8); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener(){ @Override public void onPageSelected(int position){ // TODO Auto-generated method stub radioGroup.check(position); smoothScrollTo(position); curPosition=position; curKeyValue = tabs.get(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2){ // TODO Auto-generated method stub } @Override public void onPageScrollStateChanged(int arg0){ // TODO Auto-generated method stub } }); viewPager.setCurrentItem(curPosition); } @Override public void onClick(View v) { // TODO Auto-generated method stub } private void smoothScrollTo(final int position){ final int w = radioGroup.getWidth() / radioGroup.getChildCount(); new Handler().postDelayed((new Runnable(){ @Override public void run(){ hScrollView.smoothScrollTo(((RadioButton) radioGroup.getChildAt(position)).getLeft() - w, 0); } }), 5); } }
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bg_gray" android:orientation="vertical" > <include layout="@layout/actionbar_comm" /> <HorizontalScrollView android:id="@+id/hScrollView" android:layout_width="match_parent" android:layout_height="48dp" android:background="@android:color/white" android:cacheColorHint="@android:color/transparent" android:fadingEdge="none" android:fadingEdgeLength="0dp" android:gravity="center_vertical" android:overScrollMode="never" android:scrollbars="none" > <RadioGroup android:id="@+id/radioGroup" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical" android:orientation="horizontal" > </RadioGroup> </HorizontalScrollView> <android.support.v4.view.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="16dp" android:background="@android:color/white" android:flipInterval="30" android:persistentDrawingCache="animation" /> </LinearLayout>
RadioButton --->rb_for_orders.xml
<?xml version="1.0" encoding="utf-8"?> <RadioButton xmlns:android="http://schemas.android.com/apk/res/android" style="@style/radio" android:layout_height="match_parent" android:paddingTop="8dp" android:paddingBottom="8dp" android:paddingLeft="8dp" android:paddingRight="8dp" android:textColor="@color/radio_textcolor_with_blue" />
RadioButton -->背景bg_radio_forum.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/line_bottom_with_blue_bold_for_forum" /> <item android:state_checked="false"> <shape> <solid android:color="@android:color/transparent" /> <stroke android:width="0dp" android:color="@android:color/transparent" /> <corners android:radius="0dp" /> </shape> </item> </selector>
RadioButton -->下划线line_bottom_with_blue_bold_for_forum.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:right="-3dp" android:left="-3dp" android:top="-3dp"> <shape> <stroke android:width="2dp" android:color="@color/primary" /> <solid android:color="@android:color/transparent"/> </shape> </item> </layer-list>
SmartTabLayout
http://www.jcodecraeer.com/a/opensource/2015/0331/2674.html
http://blog.csdn.net/lmj623565791/article/details/42160391
HorizontalScrollView+RadioGroup+ViewPager+FragmentPagerAdapter基本结构