2011-09-20 3 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가있는 생성자 메서드를 가지고있는 클래스가 구현을 원하는해야 알을 구현 확장 (매개 변수 메서드는 매개 변수가 없습니다) 죄송합니다, 내 영어가 잘되지 않습니다, 그래서 내가 할 수있는 Intell.My 문제에 의해 매개 변수를 보낼 수 있습니다. 내 문제는 어떻게 공용 MyClockView() {} 메서드없이 Parcelable 구현할 수 있습니다. 무슨 뜻인지 이해할 수 있니? –

+0

왜 Parcelable보기를 만들고 싶습니까? 보기에 인 텐트로 보내려는 매개 변수가있는 경우 인 텐트 추가 기능을 사용하거나 Parcelable을 구현하는 별도의 클래스를 만들어 인 텐트와 같이 사용할 수 있습니다. 뷰 자체는 Parcelable이 아니어야합니다. – brianestey

관련 문제