android - 如何在背景android附近使用删除按钮在背景内向左添加textview并向右添加edittext
问题描述
下面是我需要的图像。
你可以看到有蓝色背景,在里面,它有拖车号 1 是 textview 和 01010 是 editext (输入字段) 同样在背景之外,在蓝色背景附近有删除按钮。
我尝试的是,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/app_white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/relative_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue_light"
android:layout_marginRight="60dp"
android:layout_marginLeft="60dp">
<TextViewÒ
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trailer number"
android:padding="@dimen/margin_5"
android:layout_margin="5dp"
android:layout_alignParentLeft="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="01010"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:layout_toRightOf="@+id/relative_1"
android:background="@drawable/ic_delete_cion" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
但是删除图标根本不显示,并且行也在 01010 eddittext 中显示。
这是我的截图。
解决方案
我对您的布局进行了一些更改,它符合您的要求并适合每种设备。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/relative_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/default_blue_light">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
android:padding="10dp"
android:text="Trailer number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:background="@null"
android:inputType="number"
android:padding="5dp"
android:text="01010"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_delete_icon" />
</LinearLayout>
推荐阅读
- node.js - Node.js 服务器中的安全漏洞
- ios - UISearchController dimsBackgroundDuringPresentation 已弃用
- php - sqlsrv_fetch_array 不返回正确的行
- python - group_by ModuleNotFoundError:没有名为“dfply.group”的模块;'dfply' 不是一个包
- c# - HttpContext.RequestServices 如何无法解析范围服务?
- api - 搜索仅使用确切的关键字 - woocommerce
- angular - mat-spinner 不会停止旋转
- javascript - 如何将数字转换为文本 Javascript?
- python - mysql.connector.connect() 是否记得它的启动时间并且不显示带有时间戳的数据?
- android - 如何在点击时更新我的地图在 Google 地图中的位置?