2017-12-21 15 views
1

私のappでは、big viewが約150dpのカスタムnotificationを築いています。カスタム通知に簡易ビューを含めることができませんか?

layoutViewコンポーネントがnotification関数を作成するときappがクラッシュする原因となっている

<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" > 

    <ImageView 
     android:id="@+id/imagenotileft" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/imagenotileft" /> 

    <View 
     android:id="@+id/view" 
     android:layout_width="365dp" 
     android:layout_height="@dimen/dp_2" 
     android:layout_marginTop="@dimen/dp_23" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@+id/title" 
     android:background="@color/comunica_app_light_grey" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/view" 
     android:layout_toRightOf="@+id/imagenotileft" /> 

    <ImageView 
     android:id="@+id/imagenotiright" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:padding="10dp" /> 

</RelativeLayout> 

以下の通りであるが、それは完全にViewコンポーネントなしで膨張させるためcalled.Thereがcode一部と間違って何もないです。

エラー時のログを以下に示します。

  Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 
12-21 10:27:36.504 1701-1701/? E/StatusBar: couldn't inflate view for notification edu.uoc.app.comunica.dev/0x0 
              android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.view.View 
              Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.view.View 
              Caused by: android.view.InflateException: Binary XML file line #0: Class not allowed to be inflated android.view.View 
               at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:683) 
               at android.view.LayoutInflater.createView(LayoutInflater.java:634) 
               at android.view.LayoutInflater.onCreateView(LayoutInflater.java:700) 
               at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68) 
               at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717) 
               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785) 
               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) 
               at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) 
               at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) 
               at android.view.LayoutInflater.inflate(LayoutInflater.java:518) 
               at android.view.LayoutInflater.inflate(LayoutInflater.java:426) 
               at android.widget.RemoteViews.inflateView(RemoteViews.java:3198) 
               at android.widget.RemoteViews.apply(RemoteViews.java:3162) 
               at com.android.systemui.statusbar.BaseStatusBar.inflateViews(BaseStatusBar.java:1667) 
               at com.android.systemui.statusbar.BaseStatusBar.createNotificationViews(BaseStatusBar.java:2171) 
               at com.android.systemui.statusbar.phone.PhoneStatusBar.addNotification(PhoneStatusBar.java:1407) 
               at com.android.systemui.statusbar.BaseStatusBar$7$2.run(BaseStatusBar.java:634) 
               at android.os.Handler.handleCallback(Handler.java:751) 
               at android.os.Handler.dispatchMessage(Handler.java:95) 
               at android.os.Looper.loop(Looper.java:154) 
               at android.app.ActivityThread.main(ActivityThread.java:6077) 
               at java.lang.reflect.Method.invoke(Native Method) 
               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 
12-21 10:27:36.528 29283-29283/edu.uoc.app.comunica.dev E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: edu.uoc.app.comunica.dev, PID: 29283 
                      android.app.RemoteServiceException: Bad notification posted from package edu.uoc.app.comunica.dev: Couldn't expand RemoteViews for: StatusBarNotification(pkg=edu.uoc.app.comunica.dev user=UserHandle{0} id=0 tag=null key=0|edu.uoc.app.comunica.dev|0|null|10115: Notification(pri=0 contentView=edu.uoc.app.comunica.dev/0x7f0c002a vibrate=null sound=null tick defaults=0x0 flags=0x10 color=0x00000000 vis=PRIVATE)) 
                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631) 
                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                       at android.os.Looper.loop(Looper.java:154) 
                       at android.app.ActivityThread.main(ActivityThread.java:6077) 
                       at java.lang.reflect.Method.invoke(Native Method) 
                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 

ログから原因を突き止めることはできません。

解決策を提供してください。

+0

ここで、このレイアウトは 'android:layout_below = "@ + id/send_date" 'ですか? 、 'TextView'と' View'は同じIDを持っていますなぜですか? –

+0

申し訳ありませんが、質問は編集されました –

答えて

0

あなたはビュー

android:id="@+id/title" 

の両方のために、このIDを追加し、以下のIDが表示

@+id/send_date 

のいずれにも割り当てられていない、これはあなたがしなければならない問題

+0

申し訳ありませんが、質問は編集されています。 –

+0

レイアウトファイルの最初の行が欠落しています。すなわち、<?xml version = "1.0" encoding = "utf-8"?>。これを追加して確認してください。 –

0

かもしれカスタムビューに必要なすべてのコンストラクタを追加します。あなたがアンドロイドスタジオを使用する場合は、Code-> Generate、次に "constructor"を検索し、使用可能なすべてのコンストラクタをチェックし、次のウィンドウですべてのクラスプロパティのチェックを外す必要があります。

public class CustomView extends View {  
    public CustomView(Context context) { 
     super(context); 
    } 

    public CustomView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(attrs); 
    } 

    public CustomView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     init(attrs); 
    } 
} 
関連する問題