下面是我需要的图片。
你可以看到蓝色的背景,里面有
拖车编号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 edditext中。
这是我的截图。
最佳答案
我对你的布局做了一些改变,它符合你的要求,适合每一个设备。
<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>