Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The View does not fit if app length is more than 6 #26

Closed
BraveEvidence opened this issue Jul 24, 2018 · 10 comments
Closed

The View does not fit if app length is more than 6 #26

BraveEvidence opened this issue Jul 24, 2018 · 10 comments

Comments

@BraveEvidence
Copy link

Hi,

I want the app length to be 10.If I increase the app:length attribute to 10 the view does not fit and I can see only 6 boxes. Let me know if there is any work around?

@deepaksachdeva
Copy link

deepaksachdeva commented Jul 26, 2018

@PritishSawant Have a look this, it may help you.

Replace:

LinearLayout.LayoutParams params =
         new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

To:

 LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f);

@BraveEvidence
Copy link
Author

@deepaksachdeva does not work.

@deepaksachdeva
Copy link

@PritishSawant Still fields are not in a single row or you are not able to see the entered text now. Please send me your screenshot too.

@BraveEvidence
Copy link
Author

BraveEvidence commented Jul 27, 2018

@deepaksachdeva
screen shot 2018-07-27 at 7 28 15 am

This is the xml

<com.mukesh.OtpView android:id="@+id/otp_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:background="#cccccc" android:inputType="number" app:otp="1234567890" android:textColor="@color/colorPrimary" app:length="10" />

This is the change which you told me to make

LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,1.0f);

@mukeshsolanki
Copy link
Owner

have you tried app:space to reduce the space between digits?

@BraveEvidence
Copy link
Author

@mukeshsolanki does not work

@mukeshsolanki
Copy link
Owner

@PritishSawant can you try the latest version 2.0.0

@BraveEvidence
Copy link
Author

I tried with version 2 and the max it can fit is 8 with no margins on Start and End even after adding margins
screen shot 2018-08-28 at 8 11 08 am

@mukeshsolanki
Copy link
Owner

that depends on the screen size im afraid that's the limit for now

@pravingaikwad07
Copy link

For otpLength = n (where n is any number) , try this:

Kotlin code:

val otp_view = findViewById<OtpView>(R.id.otp_view)
otp_view.getViewTreeObserver()
            .addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
                override fun onPreDraw(): Boolean {
                    if (otp_view.getViewTreeObserver().isAlive()) otp_view.getViewTreeObserver()
                        .removeOnPreDrawListener(this)
                    val viewWidth = otp_view.width
                    val otpCount = otp_view.itemCount //this is otp length lets say 8

                    otp_view.itemWidth = (viewWidth / otpCount) - (otp_view.itemSpacing)

                  //  Log.d(TAG, "onPreDraw: $viewWidth :: $otpCount :: ${otp_view.itemWidth}")

                    return true
                }
            })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants