0

내가 CustomUI.java 내가 제작하는 주문형 UI

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.missedcall" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="16" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.missedcall.CustomUI" 
      android:label="@string/title_activity_custom_ui" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

내가 AndroidManifest.xml을

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".CustomUI" > 

    <com.example.missedcall.CustomUI 
     android:id="@+id/single_spinner" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 
    </com.example.missedcall.CustomUI> 

</RelativeLayout> 

를 레이아웃 custom_ui.xml 파일을 만든

public class CustomUI extends View { 

    Bitmap icon; 
    float left=0; 

    public CustomUI(Context context) { 
     super(context); 
     icon=BitmapFactory.decodeResource(getResources(), R.drawable.icon); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     // TODO Auto-generated method stub 
     super.onDraw(canvas); 
     canvas.drawBitmap(icon, left, 0, null); 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
      setMeasuredDimension(250, 100); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     // TODO Auto-generated method stub 
     if(event.getAction()==event.ACTION_SCROLL){ 
      left=event.getX(); 
     } 
     if(left>=200){ 
      //do some activity; 
     } 
     return true; 
    } 
} 

파일을 만든 (기준보기를 확장) 보여 주는 그래픽 레이아웃을 잘 보여 주지만, 실행할 때 실행 n은 빈 레이아웃을 표시하고 두 번째 nc 이후에 오류를 표시합니다. 앱을 잃어 버린다. 이 문제를 해결하고 Android에서 맞춤 UI를 만드는 데 도움을주세요.

로그 파일 : http://i.stack.imgur.com/o4L6o.jpg 또는 https://dl.dropboxusercontent.com/u/6608612/log.JPG

+0

이 생성자가 될 수 ..

CustomUi customUi = (CustomUi) findViewById(R.id.single_spinner); 

희망이 도움으로 CustomUi를 선언? 따라 나는 그것을 변경 –

답변

0

CustomUi 클래스의 컨텍스트와 함께 AttributeSet 매개 변수를 갖는 생성자를 만들어야합니다. 메인 클래스의 다음

public CustomUi(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    icon=BitmapFactory.decodeResource(getResources(), R.drawable.icon); 
} 

+0

을 변경 한 후에 작동합니다. 이제 올바르게 작동합니다. 도움을 주셔서 감사합니다. :) – user2290872

0

문제는 여기에 있습니다 :

<activity 
     android:name="com.example.missedcall.CustomUI" 

당신은 여기 acitivity 클래스를 제공해야합니다. 귀하가 제공 한 것이 귀하의 CustomView 클래스입니다.

+0

... 인수없이 시도 <활동 안드로이드 : 이름 = "com.example.missedcall.Main" 및 주요 활동에서 활동하고 된 setContentView (R.layout.custom_ui)와 연장; 및 여전히 1 초 후에 닫힙니다. 문제 해결에 도움주세요. – user2290872

+0

예요. 이제 manfist의 활동 클래스를 변경하고 CustomUi.java 파일의 생성자 – user2290872