Android Buffet custom Control (i) custom control from layout
- Android Buffet custom Control one from layout custom control
- customizing controls from layout
customizing controls from layout
Create a new layout in layout
<?xml version= "1.0" encoding= "Utf-8"?><relativelayout xmlns:android="Http://schemas.android.com/apk/res/android" android:layout_width="Match_parent" android:layout_height="Match_parent" > <TextViewandroid:id= "@+id/tv_text"android:layout_width="Wrap_ Content "android:layout_height=" wrap_content "/> <ImageViewandroid:id="@+id/iv_image"android:layout_width= "Wrap_content" android:layout_height="Wrap_content"android:layout_below="@+id/tv_text" /> </relativelayout>
To create a new class in SRC
The inherited class is the same as the root view of the previous step layout
Public class customview extends relativelayout{the view contained in the//layoutPrivateView Mrootview;PrivateTextView Mtextview;PrivateImageView Mimageview;//Overload one-parameter construction method Public CustomView(Context context) { This(Context,NULL);}//Overload two-parameter construction method Public CustomView(context context, AttributeSet attrs) {Super(context, attrs); Mrootview=layoutinflater.from (context). Inflate (R.layout.layout_view, This,true); mtextview= (TextView) Mrootview.findviewbyid (R.id.tv_text); mimageview= (ImageView) Mrootview.findviewbyid (r.id.iv_image);}//Custom method Public void SetText(String text) {Mtextview.settext (text);}//Custom method Public void Setimageresource(intResId) {Mimageview.setimageresource (resId);}}
It is now possible to use it as a normal control.
Android Buffet custom Control (i) custom control from layout