修改BUG
修改飘屏,飘屏不合适
This commit is contained in:
@@ -51,79 +51,18 @@ public class CurrencyExchangeActivity extends BaseMvpActivity<CurrencyExchangePr
|
||||
mBinding.t5.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (walletBean == null){
|
||||
return;
|
||||
}
|
||||
float earnings_num = Float.parseFloat(walletBean.getEarnings());
|
||||
int earnings_num_int = (int) Math.floor(earnings_num);
|
||||
// 获取 earnings 值
|
||||
String earnings = truncateToFirstDecimalPlace(walletBean.getEarnings());
|
||||
mBinding.etCustomAmount.setText(earnings);
|
||||
mBinding.etCustomAmount.setText(earnings_num_int+"");
|
||||
}
|
||||
});
|
||||
|
||||
TextInputEditText etCustomAmount = mBinding.etCustomAmount;
|
||||
|
||||
// 限制只能输入数字和小数点后一位
|
||||
etCustomAmount.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
|
||||
etCustomAmount.setFilters(new InputFilter[]{ (source, start, end, dest, dstart, dend) -> {
|
||||
// 防止输入负号
|
||||
if (source.toString().contains("-")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String newText = dest.toString().substring(0, dstart) + source.toString() + dest.toString().substring(dend);
|
||||
|
||||
// 检查小数点
|
||||
if (newText.contains(".")) {
|
||||
String[] splitResult = newText.split("\\.");
|
||||
if (splitResult.length > 1 && splitResult[1].length() > 1) {
|
||||
// 小数点后只能有一位
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// 可选:限制最大长度
|
||||
if (newText.length() > 10) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return null;
|
||||
}});
|
||||
|
||||
// 可选:添加 TextWatcher 来监听输入内容变化
|
||||
etCustomAmount.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
// 如果以小数点开头,自动补 0
|
||||
if (s.toString().startsWith(".")) {
|
||||
s.insert(0, "0");
|
||||
}
|
||||
// 如果以多个 0 开头,只保留一个
|
||||
if (s.toString().startsWith("0") && s.toString().length() > 1 && s.toString().charAt(1) != '.') {
|
||||
s.delete(0, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
private String truncateToFirstDecimalPlace(String value) {
|
||||
if (TextUtils.isEmpty(value)) return "0.0";
|
||||
|
||||
int dotIndex = value.indexOf('.');
|
||||
if (dotIndex == -1) {
|
||||
return value + ".0"; // 没有小数点,默认加 .0
|
||||
}
|
||||
|
||||
String integerPart = value.substring(0, dotIndex);
|
||||
String decimalPart = value.substring(dotIndex + 1);
|
||||
|
||||
if (decimalPart.length() >= 1) {
|
||||
return integerPart + "." + decimalPart.charAt(0); // 只取小数点后一位
|
||||
} else {
|
||||
return integerPart + ".0"; // 小数点后为空,默认加 0
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@@ -139,6 +78,7 @@ public class CurrencyExchangeActivity extends BaseMvpActivity<CurrencyExchangePr
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
MvpPre.wallet();
|
||||
MvpPre.getWalletConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
android:layout_centerInParent="true"
|
||||
android:hint="请输入需要兑换的钻石数量"
|
||||
android:textColorHint="@color/color_FF999999"
|
||||
android:inputType="number|numberDecimal"
|
||||
android:inputType="number"
|
||||
android:textSize="@dimen/sp_14"/>
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -8,62 +8,61 @@
|
||||
android:layout_marginEnd="@dimen/dp_16"
|
||||
android:layout_marginBottom="@dimen/dp_10">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
<com.xscm.moduleutil.widget.GifAvatarOvalView
|
||||
android:id="@+id/task_pic"
|
||||
android:layout_width="@dimen/dp_40"
|
||||
android:layout_height="@dimen/dp_40"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@mipmap/task_lock"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:layout_marginEnd="@dimen/dp_8"
|
||||
android:text="任务名称"
|
||||
android:textColor="@color/color_FF333333"
|
||||
android:textSize="@dimen/sp_14"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
app:layout_constraintEnd_toStartOf="@+id/task_type"
|
||||
app:layout_constraintStart_toEndOf="@id/task_pic"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.xscm.moduleutil.widget.GifAvatarOvalView
|
||||
android:id="@+id/task_pic"
|
||||
android:layout_width="@dimen/dp_40"
|
||||
android:layout_height="@dimen/dp_40"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:src="@mipmap/task_lock"
|
||||
android:scaleType="fitCenter"/>
|
||||
<TextView
|
||||
android:id="@+id/task_jb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_21"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:text="金币"
|
||||
android:textColor="@color/color_FF999999"
|
||||
android:textSize="@dimen/sp_14"
|
||||
app:layout_constraintStart_toEndOf="@id/task_pic"
|
||||
app:layout_constraintTop_toBottomOf="@id/task_name" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_21"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:layout_toEndOf="@id/task_pic"
|
||||
android:text="任务名称"
|
||||
android:textColor="@color/color_FF333333"
|
||||
android:textSize="@dimen/sp_14" />
|
||||
<TextView
|
||||
android:id="@+id/task_jb_number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_21"
|
||||
android:layout_marginStart="@dimen/dp_4"
|
||||
android:text="+10"
|
||||
android:textColor="#FF8827"
|
||||
android:textSize="@dimen/sp_14"
|
||||
app:layout_constraintStart_toEndOf="@id/task_jb"
|
||||
app:layout_constraintTop_toBottomOf="@id/task_name" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_jb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_21"
|
||||
android:layout_below="@id/task_name"
|
||||
android:layout_marginStart="@dimen/dp_2"
|
||||
android:layout_toEndOf="@id/task_pic"
|
||||
android:text="金币"
|
||||
android:textColor="@color/color_FF999999"
|
||||
android:textSize="@dimen/sp_14" />
|
||||
<TextView
|
||||
android:id="@+id/task_type"
|
||||
android:layout_width="@dimen/dp_60"
|
||||
android:layout_height="@dimen/dp_30"
|
||||
android:gravity="center"
|
||||
android:textColor="#C134EE"
|
||||
android:background="@drawable/bg_r99_e24171"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_jb_number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/dp_21"
|
||||
android:layout_below="@id/task_name"
|
||||
android:layout_toEndOf="@id/task_jb"
|
||||
android:text="+10"
|
||||
android:textColor="#FF8827"
|
||||
android:textSize="@dimen/sp_14" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_type"
|
||||
android:layout_width="@dimen/dp_60"
|
||||
android:layout_height="@dimen/dp_30"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:textColor="#C134EE"
|
||||
android:background="@drawable/bg_r99_e24171" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
Reference in New Issue
Block a user