支付界面

转自

http://blog.csdn.net/qq_21445563/article/details/53927334

问题描述:先看页面


[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="@color/pub_window_bg" >  
  6.   
  7.     <LinearLayout  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:orientation="vertical"  
  11.         android:paddingTop="10dp" >  
  12.   
  13.         <RelativeLayout  
  14.             android:layout_width="fill_parent"  
  15.             android:layout_height="wrap_content"  
  16.             android:background="@color/white"  
  17.             android:orientation="vertical"  
  18.             android:padding="10dp" >  
  19.   
  20.             <TextView  
  21.                 android:id="@+id/tvTitle"  
  22.                 android:layout_width="wrap_content"  
  23.                 android:layout_height="wrap_content"  
  24.                 android:text="大家帮名称"  
  25.                 android:textColor="#505050"  
  26.                 android:textSize="16sp" />  
  27.   
  28.             <TextView  
  29.                 android:id="@+id/tvTitleContent"  
  30.                 android:layout_width="wrap_content"  
  31.                 android:layout_height="wrap_content"  
  32.                 android:layout_marginLeft="10dp"  
  33.                 android:layout_toRightOf="@id/tvTitle"  
  34.                 android:ellipsize="end"  
  35.                 android:singleLine="true"  
  36.                 android:text="联想6540安装-现场安装"  
  37.                 android:textColor="#505050"  
  38.                 android:textSize="16sp" />  
  39.   
  40.             <TextView  
  41.                 android:id="@+id/tvMoneyTitle"  
  42.                 android:layout_width="wrap_content"  
  43.                 android:layout_height="wrap_content"  
  44.                 android:layout_below="@id/tvTitle"  
  45.                 android:layout_marginTop="5dp"  
  46.                 android:text="支持金额"  
  47.                 android:textColor="#505050"  
  48.                 android:textSize="14sp" />  
  49.   
  50.             <TextView  
  51.                 android:id="@+id/tvMoney"  
  52.                 android:layout_width="wrap_content"  
  53.                 android:layout_height="wrap_content"  
  54.                 android:layout_below="@id/tvTitle"  
  55.                 android:layout_marginLeft="10dp"  
  56.                 android:layout_marginTop="5dp"  
  57.                 android:layout_toRightOf="@id/tvMoneyTitle"  
  58.                 android:text="支持金额"  
  59.                 android:textColor="#505050"  
  60.                 android:textSize="14sp" />  
  61.         </RelativeLayout>  
  62.         <!-- 支付 -->  
  63.         <LinearLayout  
  64.             android:layout_width="fill_parent"  
  65.             android:layout_height="wrap_content"  
  66.             android:layout_marginTop="10dp"  
  67.             android:background="@color/white"  
  68.             android:orientation="vertical" >  
  69.   
  70.             <LinearLayout  
  71.                 android:layout_width="fill_parent"  
  72.                 android:layout_height="wrap_content"  
  73.                 android:layout_marginBottom="11dp"  
  74.                 android:layout_marginLeft="10dp"  
  75.                 android:layout_marginTop="12dp"  
  76.                 android:background="@drawable/pub_bg_selector"  
  77.                 android:gravity="center_vertical"  
  78.                 android:orientation="horizontal" >  
  79.   
  80.                 <TextView  
  81.                     android:layout_width="wrap_content"  
  82.                     android:layout_height="wrap_content"  
  83.                     android:layout_centerVertical="true"  
  84.                     android:text="使用钱包付款"  
  85.                     android:textColor="#505050"  
  86.                     android:textSize="15sp" />  
  87.   
  88.                 <TextView  
  89.                     android:id="@+id/tvWalletMoney"  
  90.                     android:layout_width="wrap_content"  
  91.                     android:layout_height="wrap_content"  
  92.                     android:layout_marginLeft="5dp"  
  93.                     android:layout_weight="1"  
  94.                     android:ellipsize="end"  
  95.                     android:singleLine="true"  
  96.                     android:text=" (可用余额:¥0) "  
  97.                     android:textColor="#858585"  
  98.                     android:textSize="15sp" />  
  99.   
  100.                 <CheckBox  
  101.                     android:id="@+id/cbUseWallet"  
  102.                     android:layout_width="wrap_content"  
  103.                     android:layout_height="wrap_content"  
  104.                     android:layout_alignParentRight="true"  
  105.                     android:layout_centerVertical="true"  
  106.                     android:layout_marginRight="20dp"  
  107.                     android:button="@drawable/cb_show"  
  108.                     android:drawableLeft="@null" />  
  109.             </LinearLayout>  
  110.   
  111.             <include layout="@layout/include_line_h" />  
  112.   
  113.             <RadioGroup  
  114.                 android:id="@+id/radioGroupPay"  
  115.                 android:layout_width="match_parent"  
  116.                 android:layout_height="wrap_content"  
  117.                 android:background="@color/white"  
  118.                 android:orientation="vertical" >  
  119.   
  120.                 <RadioButton  
  121.                     android:id="@+id/radioAlipay"  
  122.                     android:layout_width="match_parent"  
  123.                     android:layout_height="wrap_content"  
  124.                     android:button="@null"  
  125.                     android:checked="true"  
  126.                     android:drawableLeft="@drawable/img_alpay"  
  127.                     android:drawablePadding="10dp"  
  128.                     android:drawableRight="@drawable/selector_gender_woman"  
  129.                     android:paddingBottom="10dp"  
  130.                     android:paddingLeft="10dp"  
  131.                     android:paddingRight="25dp"  
  132.                     android:paddingTop="10dp"  
  133.                     android:text="支付宝"  
  134.                     android:textColor="#858585" />  
  135.   
  136.                 <RadioButton  
  137.                     android:id="@+id/radioWxpay"  
  138.                     android:layout_width="match_parent"  
  139.                     android:layout_height="wrap_content"  
  140.                     android:button="@null"  
  141.                     android:drawableLeft="@drawable/img_wechat"  
  142.                     android:drawablePadding="10dp"  
  143.                     android:drawableRight="@drawable/selector_gender_woman"  
  144.                     android:paddingBottom="10dp"  
  145.                     android:paddingLeft="10dp"  
  146.                     android:paddingRight="25dp"  
  147.                     android:paddingTop="10dp"  
  148.                     android:text="微信钱包"  
  149.                     android:textColor="#858585" />  
  150.             </RadioGroup>  
  151.   
  152.             <include layout="@layout/include_line_h" />  
  153.         </LinearLayout>  
  154.     </LinearLayout>  
  155.   
  156.     <LinearLayout  
  157.         android:layout_width="fill_parent"  
  158.         android:layout_height="49dp"  
  159.         android:layout_alignParentBottom="true"  
  160.         android:background="#80FFFFFF"  
  161.         android:gravity="center_vertical"  
  162.         android:orientation="horizontal" >  
  163.   
  164.         <TextView  
  165.             android:layout_width="wrap_content"  
  166.             android:layout_height="wrap_content"  
  167.             android:gravity="center"  
  168.             android:paddingLeft="15dp"  
  169.             android:text="共支付:"  
  170.             android:textColor="#858585"  
  171.             android:textSize="14sp" />  
  172.   
  173.         <TextView  
  174.             android:layout_width="wrap_content"  
  175.             android:layout_height="wrap_content"  
  176.             android:text="¥"  
  177.             android:textColor="#df5132"  
  178.             android:textSize="18sp" />  
  179.   
  180.         <TextView  
  181.             android:id="@+id/tvPayMoney"  
  182.             android:layout_width="wrap_content"  
  183.             android:layout_height="wrap_content"  
  184.             android:ellipsize="end"  
  185.             android:maxLength="7"  
  186.             android:minWidth="80dp"  
  187.             android:singleLine="true"  
  188.             android:text="100000"  
  189.             android:textColor="#df5132"  
  190.             android:textSize="18sp" />  
  191.   
  192.         <com.heiyue.ui.ButtonTouch  
  193.             android:id="@+id/btnSubmit"  
  194.             android:layout_width="wrap_content"  
  195.             android:layout_height="match_parent"  
  196.             android:layout_weight="1"  
  197.             android:background="@drawable/btn_orange_corner_no"  
  198.             android:gravity="center"  
  199.             android:text="去支付"  
  200.             android:textColor="@color/white"  
  201.             android:textSize="16sp" />  
  202.     </LinearLayout>  
  203.   
  204. </RelativeLayout>  


手动设置选择哪种支付方式

[java]  view plain  copy
  1. cbUseWallet.setOnClickListener(new OnClickListener() {  
  2.   
  3.             @Override  
  4.             public void onClick(View v) {  
  5.                 choosePayType(0);  
  6.             }  
  7.         });  
  8.   
  9.         radioAlipay.setOnClickListener(new OnClickListener() {  
  10.   
  11.             @Override  
  12.             public void onClick(View v) {  
  13.                 choosePayType(1);  
  14.             }  
  15.         });  
  16.   
  17.         radioWxpay.setOnClickListener(new OnClickListener() {  
  18.   
  19.             @Override  
  20.             public void onClick(View v) {  
  21.                 choosePayType(2);  
  22.             }  
  23.         });  

[java]  view plain  copy
  1. /** 
  2.      * 选择支付方式;三者只能选择一种 
  3.      *  
  4.      * @param type 
  5.      *            0,钱包支付;1,支付宝支付;2微信支付 
  6.      */  
  7.     private void choosePayType(int type) {  
  8.         cbUseWallet.setChecked(false);  
  9.         radioGroupPay.clearCheck();  
  10.   
  11.         switch (type) {  
  12.         case 0:  
  13.             cbUseWallet.setChecked(true);  
  14.             break;  
  15.         case 1:  
  16.             radioAlipay.setChecked(true);  
  17.             break;  
  18.         case 2:  
  19.   
  20.             radioWxpay.setChecked(true);  
  21.             break;  
  22.   
  23.         default:  
  24.             break;  
  25.         }  
  26.   
  27.     }  

解决方案:

1.

RadioGroup的clearCheck方法

设置RadioButton为初始的都不选中状态。在做完点击事件后,RadioGroup.clearCheck();就可以了。直接挨个setChecked(false)会出问题,下次点击不会变为选中状态

2.

设置RadioButton的默认选中, 使用setChecked(true) 这样会使RadioButton一直处于选中状态. 

我们应该给RadioGroup 设置选中的RadioButton  

代码:

radioGroup.check(radioButton.getId()); 

如何设置radioButton选中和未选中的图标不一样?

在drawable文件夹下面新建一个资源文件radiobutton.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/select" ></item>
    <item android:state_checked="false" android:drawable="@drawable/select_white"></item>
</selector>
设置
 android:drawableRight="@drawable/color_radiobutton"
android:button="@null"//取消默认的radiobutton







猜你喜欢

转载自blog.csdn.net/qq_34602647/article/details/79167686