2

I am facing an issue maybe I might have a device issue.

Single Linear Layout

What I am Doing : Creating login form with three view i.e. Edit Text, Button(initially visibility gone) , CheckBox.

What I am Facing : As soon as I check with check box, button get visible and check box moves below since I have Provided margin Top and my view is like this :

Edit Text Button(visibility gone) Checkbox(with margin top)

As soon as I am checking on checkBox I am making the button visible but I am facing two issue.

Issue 1: Check box when checked the text moves a litte upward but button tint do not move It does remain fixed

Issue 2: Since I have given margin top and button is not visible currently when i am checking the whole check box view is now taking margin from button which earlier it was taking from edit text and still Issue 1 is observed again

My xml code is here :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="0dip"
    tools:context=".LoginActivity">

    <com.medmainfomatix.VoIPvoiceapp.MyViewPager
        android:id="@+id/viewPagerVertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="150dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/layout_sms"
        android:gravity="center_horizontal"
        android:orientation="vertical">



        <android.support.design.widget.TextInputLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="50dp"
            android:layout_gravity="center"
            >

            <EditText
                android:id="@+id/loginNo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:minWidth="200dp"
                android:layout_gravity="center_horizontal"
                android:textSize="25sp"
                android:maxLength="10"
                android:textColor="@color/white"
                android:hint="@string/msg_enter_mobile"
                android:digits="1234567890"
                android:textCursorDrawable="@null"
                android:inputType="phone">

                <requestFocus />

            </EditText>

        </android.support.design.widget.TextInputLayout>

        <Button
            android:id="@+id/btn_request_sms"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="NEXT"
            android:minHeight="50dp"
            android:minWidth="170dp"
            android:background="@color/btnclr"
            android:textColor="@color/pink"
            android:textSize="20sp"
            android:textStyle="bold"
            android:visibility="gone" />

      <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_marginTop="200dp"
            android:layout_gravity="center_horizontal"
            android:textColor="@color/white"
            android:buttonTint="@color/white"/>


    </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/layout_otp"
            android:gravity="center_horizontal"
            android:orientation="vertical">


            <TextView
                android:id="@+id/otptext1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_marginBottom="15dp"
                android:paddingLeft="40dp"
                android:paddingRight="40dp"
                android:layout_gravity="center"
                android:text="@string/msg_manual_otp"
                android:textColor="@android:color/white"
                android:textSize="12dp"
                />

            <android.support.design.widget.TextInputLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="50dp"
                android:layout_gravity="center"
                >



            <EditText
                android:id="@+id/inputOtp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:minWidth="120dp"
                android:layout_gravity="center"
                android:textSize="25sp"
                android:maxLength="6"
                android:textColor="@color/white"
                android:hint="@string/lbl_enter_otp"
                android:digits="1234567890"
                android:textCursorDrawable="@null"
                android:inputType="number">

                <requestFocus />

            </EditText>

            </android.support.design.widget.TextInputLayout>

            <Button
                android:id="@+id/loginButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="15dp"
                android:text="VERIFY"
                android:background="@color/btnclr"
                android:minHeight="50dp"
                android:minWidth="170dp"
                android:textColor="@color/pink"
                android:textSize="20sp"
                android:textStyle="bold"
                />

        </LinearLayout>
    </com.medmainfomatix.VoIPvoiceapp.MyViewPager>

</RelativeLayout>

See Only for Layout SMS since I have used view pager dont look at Otp section. I am thinking to increase the text size of checkbox.

Here are two Screenshot sorry for the delay. Before

After

SamH67
  • 319
  • 1
  • 4
  • 14

2 Answers2

1

When the button is visibility.GONE it means it doesn't take space in the screen , when you make him visibility.VISIBLE it now takes a place and the other views react to it if not properly set , best solution is to use visibilty.INVISIBLE which will make it invisible but takes its place in the screen , that way nothing will be moved when it turns visible, and then you can rearrange the screen easily

you can check out this for more Android : difference between invisible and gone?

Community
  • 1
  • 1
yanivtwin
  • 617
  • 8
  • 32
  • Perfect but Issue 1 is still unresolved please help. Why this text is moveing upward when i check button of checkbox – SamH67 Dec 01 '16 at 08:35
  • can you put two screenshots before and after check ? – yanivtwin Dec 01 '16 at 08:39
  • though i have to test it on emulator that is the reason for uploading late sorry because my emulator is Super slow. – SamH67 Dec 01 '16 at 09:58
  • Worked thank you for part of your answer. You know earlier i was trying setting this element at the parent bottom buttom i stupidly did this on check method Box.setGravity(0); thats why it was flying like a bird :P – SamH67 Dec 01 '16 at 10:09
  • Atleast do the courtesy to like the question if you attempt an answer though – SamH67 Dec 01 '16 at 10:10
0

Try to invalidate() layout immediate after checkbox is checked.

Piyush
  • 18,895
  • 5
  • 32
  • 63