将setError视图位置置于不同位置

时间:2017-08-31 09:00:10

标签: android android-edittext position

我是Android新手。我使用 setError 的setError,但它出现在其他位置,然后是它的实际位置。我在这张图片中显示的位置:

image

但是,我需要它在editText上:

like this

我也不想使用textInputLayout。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:gradient="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:weightSum="2">


<com.dynamitechetan.flowinggradient.FlowingGradient
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    gradient:alpha="4"
    gradient:transition_drawable="@drawable/login_bg_translate_anim"
    gradient:transition_duration="1000" />


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="2">

    <LinearLayout
        android:id="@+id/sign_in_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:orientation="vertical"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="90dp"
        android:visibility="visible"
        android:weightSum="2"
        tools:visibility="visible">

        <Button
            android:id="@+id/sign_in_button"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/round_btn_shape"
            android:foreground="?attr/selectableItemBackground"
            android:text="Sign in With Google"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:theme="@style/ThemeOverlay.MyDarkButton" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginTop="16dp"
            android:gravity="center_horizontal"
            android:text="OR"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#fff"
            android:textSize="20dp" />

        <Button
            android:id="@+id/phone_login_slct_btn"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/round_btn_shape"
            android:foreground="?attr/selectableItemBackground"
            android:gravity="center"
            android:onClick="onClickPhone"
            android:text="Sign in With Phone"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:theme="@style/ThemeOverlay.MyDarkButton" />

    </LinearLayout>

    <android.support.v7.widget.CardView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_above="@+id/sign_in_layout"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:background="?attr/selectableItemBackground"
        app:cardBackgroundColor="#fff"
        app:cardCornerRadius="25dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:foreground="?attr/selectableItemBackground"
            android:src="@drawable/ic_explicit_black_24dp" />
    </android.support.v7.widget.CardView>

</RelativeLayout>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:weightSum="1">

        <ProgressBar
            android:id="@+id/progressBar_phone"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".1"
            android:indeterminate="true"
            android:visibility="invisible" />

        <RelativeLayout
            android:id="@+id/relative_layout_all_element_phone_auth"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="0.9"
            android:background="#4D0178B8"
            android:gravity="center_vertical">

            <LinearLayout
                android:id="@+id/phone_auth_fields"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingLeft="16dp"
                android:paddingRight="16dp">

                <LinearLayout
                    android:id="@+id/register_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:animateLayoutChanges="true"
                    android:orientation="horizontal"
                    android:visibility="visible"
                    android:weightSum="1.0">

                    <android.support.v7.widget.AppCompatEditText
                        android:id="@+id/field_phone_number"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.7"
                        android:hint="Phone Number"
                        android:inputType="phone"
                        android:textColor="@color/white"
                        android:textColorHint="#CECECE"
                        android:textCursorDrawable="@drawable/custom_cursor"
                        android:textStyle="bold"
                        app:backgroundTint="@color/white" />

                    <Button
                        android:id="@+id/button_start_verification"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.3"
                        android:foreground="?attr/selectableItemBackground"
                        android:text="Start"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold"
                        android:theme="@style/ThemeOverlay.MyDarkButton" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/otpcheck_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:animateLayoutChanges="true"
                    android:orientation="vertical"
                    android:visibility="gone"
                    android:weightSum="2.0">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="horizontal"
                        android:weightSum="2">

                        <android.support.v7.widget.AppCompatEditText
                            android:id="@+id/show_phone_number"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1.0"
                            android:focusable="false"
                            android:focusableInTouchMode="false"
                            android:hint="Phone Number"
                            android:inputType="phone"
                            android:textColor="@color/white"
                            android:textColorHint="#CECECE"
                            android:textCursorDrawable="@drawable/custom_cursor"
                            app:backgroundTint="@color/white" />

                        <android.support.v7.widget.AppCompatEditText
                            android:id="@+id/field_verification_code"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1.0"
                            android:hint="Verification Code"
                            android:inputType="phone"
                            android:textColor="@color/white"
                            android:textColorHint="#CECECE"
                            android:textCursorDrawable="@drawable/custom_cursor"
                            app:backgroundTint="@color/white" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="horizontal"
                        android:weightSum="2">

                        <Button
                            android:id="@+id/button_verify_phone"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1.0"
                            android:foreground="?attr/selectableItemBackground"
                            android:text="Verify"
                            android:theme="@style/ThemeOverlay.MyDarkButton" />

                        <Button
                            android:id="@+id/button_resend"
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1.0"
                            android:foreground="?attr/selectableItemBackground"
                            android:text="Resend"
                            android:theme="@style/ThemeOverlay.MyDarkButton" />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

0 个答案:

没有答案