代码之家  ›  专栏  ›  技术社区  ›  Themelis

android:widget显示错误视图

  •  1
  • Themelis  · 技术社区  · 8 年前

    我用向导创建了一个小部件。然后我定制了布局。 我试图运行,但我得到的只是小部件__的错误视图。 加载小部件时出现问题 __

    检查日志时发现此错误:

    W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view
    

    它说系统找不到任何视图,但我的布局是在 res/layout/ 并在widget info xml文件中声明。

    我错过了什么?这是 the project on GitHub .

    1 回复  |  直到 8 年前
        1
  •  2
  •   Elletlar FireTr3e    8 年前

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/playback_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
        <ImageView
            android:id="@+id/poster_imageview"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/ic_headset_mic_light_black_140dp" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <TextView
                android:id="@+id/title_textview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/app_name"
                android:textAlignment="center"
                android:textColor="@color/primaryTextColor"
                android:textSize="16sp" />
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="@dimen/default_text_padding">
    
                <ImageView
                    android:id="@+id/player_previous"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="32dp"
                    android:layout_marginRight="32dp"
                    android:layout_toLeftOf="@+id/player_play_pause"
                    android:src="@drawable/ic_skip_previous_white_32dp" />
    
                <ImageView
                    android:id="@+id/player_play_pause"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:src="@drawable/ic_play_arrow_white_40dp" />
    
                <ImageView
                    android:id="@+id/player_next"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="32dp"
                    android:layout_marginStart="32dp"
                    android:layout_toRightOf="@id/player_play_pause"
                    android:src="@drawable/ic_skip_next_white_32dp" />
    
    
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
    

     <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:background="?colorAccent" />