update 添加输入框间距
This commit is contained in:
@@ -7,20 +7,6 @@
|
||||
android:orientation="vertical"
|
||||
tools:context="com.jyn.vcview.simple.MainActivity">
|
||||
|
||||
<!--<com.jyn.vcview.VerificationCodeView-->
|
||||
<!--android:id="@+id/verificationcodeview"-->
|
||||
<!--android:layout_width="match_parent"-->
|
||||
<!--android:layout_height="wrap_content"-->
|
||||
<!--android:layout_marginTop="30dp"-->
|
||||
<!--android:gravity="center"-->
|
||||
<!--android:orientation="horizontal"-->
|
||||
<!--app:vcv_et_bg="@drawable/et_login_code"-->
|
||||
<!--app:vcv_et_cursor="@drawable/et_cursor"-->
|
||||
<!--app:vcv_et_inputType="number"-->
|
||||
<!--app:vcv_et_number="4"-->
|
||||
<!--app:vcv_et_text_color="@android:color/black"-->
|
||||
<!--app:vcv_et_text_size="6sp" />-->
|
||||
|
||||
<com.jyn.vcview.VerificationCodeView
|
||||
android:id="@+id/verificationcodeview"
|
||||
android:layout_width="match_parent"
|
||||
@@ -39,7 +25,8 @@
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberPassword" />
|
||||
android:inputType="numberPassword"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@@ -62,6 +61,16 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
*/
|
||||
private int mEtTextBg;
|
||||
|
||||
/**
|
||||
* 输入框间距
|
||||
*/
|
||||
private int mEtSpacing;
|
||||
|
||||
/**
|
||||
* 判断是否平分
|
||||
*/
|
||||
private boolean isBisect;
|
||||
|
||||
private boolean cursorVisible;
|
||||
|
||||
private int mCursorDrawable;
|
||||
@@ -158,14 +167,19 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
mEtNumber = typedArray.getInteger(R.styleable.vericationCodeView_vcv_et_number, 4);
|
||||
int inputType = typedArray.getInt(R.styleable.vericationCodeView_vcv_et_inputType, VCInputType.NUMBER.ordinal());
|
||||
mEtInputType = VCInputType.values()[inputType];
|
||||
Log.i("main", "mEtInputType:" + mEtInputType);
|
||||
|
||||
mEtWidth = typedArray.getDimensionPixelSize(R.styleable.vericationCodeView_vcv_et_width, 120);
|
||||
mEtTextColor = typedArray.getColor(R.styleable.vericationCodeView_vcv_et_text_color, Color.BLACK);
|
||||
mEtTextSize = typedArray.getDimensionPixelSize(R.styleable.vericationCodeView_vcv_et_text_size, 16);
|
||||
mEtTextBg = typedArray.getResourceId(R.styleable.vericationCodeView_vcv_et_bg, R.drawable.et_login_code);
|
||||
mCursorDrawable = typedArray.getResourceId(R.styleable.vericationCodeView_vcv_et_cursor, R.drawable.et_cursor);
|
||||
cursorVisible = typedArray.getBoolean(R.styleable.vericationCodeView_vcv_et_cursor_visible, true);
|
||||
|
||||
isBisect = typedArray.hasValue(R.styleable.vericationCodeView_vcv_et_spacing);
|
||||
if (isBisect) {
|
||||
mEtSpacing = typedArray.getDimensionPixelSize(R.styleable.vericationCodeView_vcv_et_spacing, 0);
|
||||
}
|
||||
Log.i("main", "isBisect:" + isBisect);
|
||||
|
||||
//释放资源
|
||||
typedArray.recycle();
|
||||
initView();
|
||||
@@ -184,15 +198,15 @@ public class VerificationCodeView extends LinearLayout implements TextWatcher, V
|
||||
}
|
||||
|
||||
private void initEditText(EditText editText, int i) {
|
||||
int childHPadding = 14;
|
||||
int childVPadding = 14;
|
||||
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(mEtWidth, mEtWidth);
|
||||
layoutParams.bottomMargin = childVPadding;
|
||||
layoutParams.topMargin = childVPadding;
|
||||
layoutParams.leftMargin = childHPadding;
|
||||
layoutParams.rightMargin = childHPadding;
|
||||
// layoutParams.bottomMargin = childVPadding;
|
||||
// layoutParams.topMargin = childVPadding;
|
||||
layoutParams.leftMargin = mEtSpacing;
|
||||
layoutParams.rightMargin = mEtSpacing;
|
||||
|
||||
layoutParams.gravity = Gravity.CENTER;
|
||||
|
||||
editText.setLayoutParams(layoutParams);
|
||||
editText.setGravity(Gravity.CENTER);
|
||||
editText.setId(i);
|
||||
|
||||
@@ -23,5 +23,8 @@
|
||||
<attr name="vcv_et_cursor" format="reference" />
|
||||
<!--是否隐藏光标-->
|
||||
<attr name="vcv_et_cursor_visible" format="boolean" />
|
||||
<!--输入框间距,不输入则代表平分-->
|
||||
<attr name="vcv_et_spacing" format="dimension|reference" />
|
||||
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user