android - 如何在 Android 上将一些视图设置为 TextInputLayout
问题描述
在我的应用程序中,我想将视图显示到TextInputLayout
.
我想要 show EditText
, TextView
(for show countDownTimer) 和View
(for show line)!
如下图:
我写了下面的代码,但我只能显示 EditText 而不能显示任何其他视图,例如 TextView 和 View!
我的 XML 代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/signInFrag_phoneInpLay"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="8dp"
app:boxStrokeColor="@color/colorAccent"
app:boxStrokeWidth="1dp">
<EditText
android:id="@+id/edtLogin1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawableEnd="@drawable/ic_phone"
android:drawableRight="@drawable/ic_phone"
android:gravity="right|center_vertical"
android:hint="Phone Number"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColorHint="#c0c0c0"
android:textSize="12sp" />
</android.support.design.widget.TextInputLayout>
如何更改我的显示代码,如上图?
解决方案
textInputLayout
您可以通过约束布局将视图设置为重叠。可能有将editText的文本与计数文本或垂直视图重叠的风险。但是我在您的文本视图中发现有文本限制。所以出于你的原因,不可能重叠计数文本视图。
代码**
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Page"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:boxStrokeColor="@color/colorAccent"
app:boxStrokeWidth="1dp"
app:hintEnabled="true"
app:layout_constraintTop_toBottomOf="@+id/title">
<EditText
android:id="@+id/edtLogin1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawableStart="@drawable/ic_action_profile"
android:gravity="left|center_vertical"
android:hint="Phone Number"
android:inputType="phone"
android:maxLength="11"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColorHint="#c0c0c0"
android:textSize="12sp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/text_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22sec"
app:layout_constraintBottom_toBottomOf="@+id/input_layout"
app:layout_constraintEnd_toEndOf="@+id/input_layout"
app:layout_constraintTop_toTopOf="@+id/input_layout" />
<View
android:id="@+id/view"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/input_layout"
app:layout_constraintEnd_toStartOf="@+id/text_view_time"
app:layout_constraintTop_toTopOf="@+id/input_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
推荐阅读
- angular - 如何使用 Http 拦截器处理 Angular 中的服务器错误
- python - vtkplotter - 如何设置颜色图
- python - 使用 django 从数据库中获取前 3 条记录
- ios - Xcode 错误 - xcodebuild: 错误:选项 'Destination' 需要至少一个形式为 'key=value' 的参数
- mongodb - 如何通过 Compass 访问远程 mongodb?
- javascript - 透视对象的 Javascript 数组
- java - QueryDsl如何使用exist()返回布尔值
- node.js - 如何在点击它下载文件之前验证预签名的 url?
- java - 如何避免在java中嵌套for循环来获取层次数据?
- java - 如何在同一台服务器上运行两个 Spring Boot 应用程序?