android - Create a custom View by inflating a layout? -
i trying create custom view replace layout use @ multiple places, struggling so.
basically, want replace this:
<relativelayout android:id="@+id/dolphinline" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerinparent="true" android:background="@drawable/background_box_light_blue" android:padding="10dip" android:layout_margin="10dip"> <textview android:id="@+id/dolphintitle" android:layout_width="200dip" android:layout_height="100dip" android:layout_alignparentleft="true" android:layout_marginleft="10dip" android:text="@string/my_title" android:textsize="30dip" android:textstyle="bold" android:textcolor="#2e4c71" android:gravity="center"/> <button android:id="@+id/dolphinminusbutton" android:layout_width="100dip" android:layout_height="100dip" android:layout_torightof="@+id/dolphintitle" android:layout_marginleft="30dip" android:text="@string/minus_button" android:textsize="70dip" android:textstyle="bold" android:gravity="center" android:layout_margintop="1dip" android:background="@drawable/button_blue_square_selector" android:textcolor="#ffffff" android:onclick="onclick"/> <textview android:id="@+id/dolphinvalue" android:layout_width="100dip" android:layout_height="100dip" android:layout_marginleft="15dip" android:background="@android:drawable/editbox_background" android:layout_torightof="@+id/dolphinminusbutton" android:text="0" android:textcolor="#2e4c71" android:textsize="50dip" android:gravity="center" android:textstyle="bold" android:inputtype="none"/> <button android:id="@+id/dolphinplusbutton" android:layout_width="100dip" android:layout_height="100dip" android:layout_torightof="@+id/dolphinvalue" android:layout_marginleft="15dip" android:text="@string/plus_button" android:textsize="70dip" android:textstyle="bold" android:gravity="center" android:layout_margintop="1dip" android:background="@drawable/button_blue_square_selector" android:textcolor="#ffffff" android:onclick="onclick"/> </relativelayout>
by this:
<view class="com.example.myquantitybox" android:id="@+id/dolphinbox" android:layout_width="fill_parent" android:layout_height="wrap_content" android:mycustomattribute="@string/my_title"/>
so, not want custom layout, want custom view (it should not possible view have child).
the thing change 1 instance of myquantitybox title. able specify in xml (as on last xml line)
how can this? should put relativelayout in xml file in /res/layout , inflate in myboxquantity class? if yes how do so?
thanks!
yes can this. relativelayout, linearlayout, etc views custom layout custom view. consider because if wanted create custom layout could.
what want create compound control. you'll create subclass of relativelayout, add our components in code (textview, etc), , in constructor can read attributes passed in xml. can pass attribute title textview.
http://developer.android.com/guide/topics/ui/custom-components.html
Comments
Post a Comment