android button paddingtop无效,android里面RadioButton设置setChecked(true)失效的解决方案

问题描述:先看页面

0818b9ca8b590ca3270a3433284dd417.png

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/pub_window_bg" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:paddingTop="10dp" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="@color/white"

android:orientation="vertical"

android:padding="10dp" >

android:id="@+id/tvTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="大家帮名称"

android:textColor="#505050"

android:textSize="16sp" />

android:id="@+id/tvTitleContent"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="10dp"

android:layout_toRightOf="@id/tvTitle"

android:ellipsize="end"

android:singleLine="true"

android:text="联想6540安装-现场安装"

android:textColor="#505050"

android:textSize="16sp" />

android:id="@+id/tvMoneyTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/tvTitle"

android:layout_marginTop="5dp"

android:text="支持金额"

android:textColor="#505050"

android:textSize="14sp" />

android:id="@+id/tvMoney"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/tvTitle"

android:layout_marginLeft="10dp"

android:layout_marginTop="5dp"

android:layout_toRightOf="@id/tvMoneyTitle"

android:text="支持金额"

android:textColor="#505050"

android:textSize="14sp" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:background="@color/white"

android:orientation="vertical" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginBottom="11dp"

android:layout_marginLeft="10dp"

android:layout_marginTop="12dp"

android:background="@drawable/pub_bg_selector"

android:gravity="center_vertical"

android:orientation="horizontal" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:text="使用钱包付款"

android:textColor="#505050"

android:textSize="15sp" />

android:id="@+id/tvWalletMoney"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="5dp"

android:layout_weight="1"

android:ellipsize="end"

android:singleLine="true"

android:text=" (可用余额:¥0) "

android:textColor="#858585"

android:textSize="15sp" />

android:id="@+id/cbUseWallet"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:layout_marginRight="20dp"

android:button="@drawable/cb_show"

android:drawableLeft="@null" />

android:id="@+id/radioGroupPay"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/white"

android:orientation="vertical" >

android:id="@+id/radioAlipay"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:button="@null"

android:checked="true"

android:drawableLeft="@drawable/img_alpay"

android:drawablePadding="10dp"

android:drawableRight="@drawable/selector_gender_woman"

android:paddingBottom="10dp"

android:paddingLeft="10dp"

android:paddingRight="25dp"

android:paddingTop="10dp"

android:text="支付宝"

android:textColor="#858585" />

android:id="@+id/radioWxpay"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:button="@null"

android:drawableLeft="@drawable/img_wechat"

android:drawablePadding="10dp"

android:drawableRight="@drawable/selector_gender_woman"

android:paddingBottom="10dp"

android:paddingLeft="10dp"

android:paddingRight="25dp"

android:paddingTop="10dp"

android:text="微信钱包"

android:textColor="#858585" />

android:layout_width="fill_parent"

android:layout_height="49dp"

android:layout_alignParentBottom="true"

android:background="#80FFFFFF"

android:gravity="center_vertical"

android:orientation="horizontal" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:gravity="center"

android:paddingLeft="15dp"

android:text="共支付:"

android:textColor="#858585"

android:textSize="14sp" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="¥"

android:textColor="#df5132"

android:textSize="18sp" />

android:id="@+id/tvPayMoney"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ellipsize="end"

android:maxLength="7"

android:minWidth="80dp"

android:singleLine="true"

android:text="100000"

android:textColor="#df5132"

android:textSize="18sp" />

android:id="@+id/btnSubmit"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:layout_weight="1"

android:background="@drawable/btn_orange_corner_no"

android:gravity="center"

android:text="去支付"

android:textColor="@color/white"

android:textSize="16sp" />

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

cbUseWallet.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

choosePayType(0);

}

});

radioAlipay.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

choosePayType(1);

}

});

radioWxpay.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

choosePayType(2);

}

});

/**

* 选择支付方式;三者只能选择一种

*

* @param type

* 0,钱包支付;1,支付宝支付;2微信支付

*/

private void choosePayType(int type) {

cbUseWallet.setChecked(false);

radioGroupPay.clearCheck();

switch (type) {

case 0:

cbUseWallet.setChecked(true);

break;

case 1:

radioAlipay.setChecked(true);

break;

case 2:

radioWxpay.setChecked(true);

break;

default:

break;

}

}

解决方案:

1.

RadioGroup的clearCheck方法

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

2.

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

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

代码:

radioGroup.check(radioButton.getId());

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值