我有一大堆表單控件,所有顯示一個圖標到左側,像這樣的:定製的LinearLayout與圖標
爲此,我有這樣的代碼:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="@dimen/icon_edittext_height"
android:layout_gravity="top"
android:layout_marginRight="@dimen/icon_edittext_marginRight"
android:layout_marginTop="@dimen/icon_edittext_margintop"
android:src="@drawable/ic_location_city_black_24dp"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/create.data.city.layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<AutoCompleteTextView
android:id="@+id/create.data.city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/create_event_city"
android:imeOptions="actionNext"
android:inputType="textCapSentences"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
</FrameLayout>
</LinearLayout>
現在因爲我有大約20個控件,我不想重複:
<LinearLayout>
<ImageView/>
<FrameLayout>
...content....
</FrameLayout>
</LinearLayout>
模式20次,但我願做這樣的事情:
<MycustomLayout>
<EditText .../>
</MycustomLayout>
<MycustomLayout>
<Spinner ... />
</MycustomLayout>
所以基本上我想創建一個擴展線性自定義佈局,我希望能夠在我使用的LinearLayout以同樣的方式使用它,同時在任何時候都有圖標。
好!你在編寫自定義佈局的時候是什麼階段? – azizbekian
我創建了一個擴展LinearLayout,放置一個圖像,但不知道如何使內的內容進入內部FrameLayout –
MichelReap