Android:在TextInputLayout中的EditText右侧显示TextView

我正在尝试创建一个如下图所示的布局

在上图中,密码字段位于TextInputLayout中,右侧还有一个TextView,指向忘记密码活动.

我使用相对布局,在没有TextInpt布局的情况下使用Textview实现EditText,如下所示

Code – xml file

<EditText
            android:id="@+id/email_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_email"
            android:drawableStart="@drawable/ic_email"
            android:drawablePadding="10dp"
            android:hint="@string/email_address"
            android:textSize="14sp"
            android:maxLines="1"
            android:inputType="textEmailAddress" />



        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        <EditText
            android:id="@+id/etxt_password_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_password"
            android:drawableStart="@drawable/ic_password"
            android:drawablePadding="10dp"
            android:textSize="14sp"
            android:hint="Password"
            android:layout_alignParentLeft="true"
            android:inputType="textPassword"
            android:maxLines="1"/>

            <TextView
                android:id="@+id/txt_forget_password"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:text="forget ?"
                android:textSize="12sp"
                android:layout_marginRight="10dp"
                android:textColor="#808080"
                />

        </RelativeLayout>

但是,如果我在EditText中添加TextInputLayout,我无法实现它..尝试并搜索了很多.

?我们如何解决上述问题

谢谢..

解决方法

尝试像这样 – 环绕相对或线性布局来获得这样的输出
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Password"/>

        </android.support.design.widget.TextInputLayout>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="Forgot Password ?"/>
    </RelativeLayout>

注意:为编辑文本设置一些填充以进行对齐

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...