简体   繁体   中英

how to make two different widgets in one screen?

我正在制作一个可以向用户显示不同手表的项目。手表具有不同的时钟刻度盘。我想在一个屏幕上制作两个不同的小部件(手表),并且手表具有不同的时间和时钟刻度盘。 ?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM