2011-09-20 55 views

回答

0

您可以制作自己的控件,然后将该控件包含在一个屏幕中两次。

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); 
    } 
} 

您可以根据需要添加额外的代码。 xml文件control_my_control是您的手表的XML。在该XML中,确保外部元素是一个元素。

对于将包含两个的这些观点,你使用它们,如:

<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> 
+0

现在我有这样的问题。 公共类MyClockView扩展视图实现Parcelable { 公共MyClockView(上下文的背景下){ }} 你知道,如果一个类扩展视图,它必须具有Context.I构造函数方法需要的类实现Parcelable,所以我可以通过Intent发送参数。我的问题是我如何实现Parcelable而没有公共MyClockView(){}方法?(参数方法没有参数) 对不起,我的英语不好,你明白我的意思吗? –

+0

为什么你想创建一个Parcelable视图?如果在视图中有一些参数需要发送给Intent,那么可以使用Intent extras,或者可以创建一个单独的类来实现Parcelable并使用它作为意图。视图本身可能不应该是可以Parcelable的。 – brianestey

相关问题