之前在写一个手机与电脑通信的程序,需要在手机端输入IP地址,Android上没有专门IP输入框,所以自己自定义了一个IP地址输入框。
1 定义该控件的布局文件
这里使用的是merge标签,主要是在主布局里面放该布局文件时,系统会自动省略merge节点并且直接添加merge节点里面的小控件,这样可以减少布局中多余的层级。当然,你也可以不用merge,使用RelativeLayout等布局,相当于布局里面嵌套小布局,这样完全可以。
这里的布局文件一共4个EditText,每个EditText中间一个.。
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:id="@+id/edit1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="@null"
android:inputType="number"
android:maxLength="3"
android:text=""/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/point"/>
<EditText
android:id="@+id/edit2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="@null"
android:inputType="number"
android:maxLength="3"
android:text=""/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/point"/>
<EditText
android:id="@+id/edit3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"