how to make two different widgets in one screen?
I'm makeing a project that can开发者_JS百科 show defferent watches to users.The watch has different clock dial.I want to make two different widgets(the watch)in one screen and the watch has different time and clock dial.How can I do it?
You can make your own control and then include that control twice in a single screen.
package com.sample.ui.control;
public class MyControl extends LinearLayout {
public MyControlContext context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.control_my_control, this);
}
}
You can add extra code as necessary. The xml file control_my_control is the XML for your watch. In that XML, be sure the outer element is a element.
For the view that will contain two of these, you use them like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.sample.ui.control.MyControl android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/control1" />
<com.sample.ui.control.MyControl android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/control2" />
</LinearLayout>
精彩评论