XML布局中我们可能会遇到需要重复放置多个相同控件的情况。
好比上图的布局,如果按照常规来做,我们会在布局中放置三个Button,外加两个View作为分界线,其代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
android:gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="1"
/>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#BFBFBF"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
android:gravity="center"
a