2013-06-27 3 views
2

Я создал и успешно запускаю свой собственный Android-виджет в Android 4.0. Для тестирования я запускаю его в Android 2.2, но он не отображает мой виджет. Он показывает сообщение Problem Loading Widget. Я установил минимальный и целевой SDK, какAndroid Виджет: работает в 4.0, но не работает в 2.2

<uses-sdk 
     android:minSdkVersion="7" 
     android:targetSdkVersion="15" /> 

Мой Компоновка XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/widgetLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/new_widget_bg" 
    android:gravity="right" > 


    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:orientation="vertical" > 
     <LinearLayout 
      android:id="@+id/title_holder" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" > 
      <LinearLayout 
       android:id="@+id/image_holder" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="8" > 

       <ImageView 
        android:id="@+id/widget_refresh_button" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/addwidbutton" /> 

       <ProgressBar 
        android:id="@+id/widget_loading" 
        style="?android:attr/progressBarStyleSmall" 
        android:layout_width="wrap_content" 
        android:layout_height="32dp" 
        android:visibility="gone" /> 
      </LinearLayout> 
      <LinearLayout 
       android:id="@+id/main_title_holder" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" > 

<TextView 
    android:id="@+id/title" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:layout_weight="1" 
    android:maxLines="1" 
    android:text="Default Project" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:textColor="#ff00a2ff" 
    android:textStyle="bold" /> 

       <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="match_parent" 
        android:layout_centerHorizontal="true" 
        android:layout_weight="1.75" 
        android:paddingBottom="5dp" 
        android:paddingLeft="5dp" 
        android:paddingRight="5dp" 
        android:paddingTop="5dp" > 

        <Button 
         android:id="@+id/widget_hrs" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:layout_gravity="center" 
         android:layout_weight="2.5" 
         android:background="@drawable/hrs_bg" 
         android:drawableLeft="@drawable/clock" 
         android:maxLines="1" 
         android:text=" --:--" 
         android:textAppearance="?android:attr/textAppearanceSmall" 
         android:textColor="#ffffff" 
         android:textStyle="bold" /> 

       </RelativeLayout> 
      </LinearLayout> 
     </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="1sp" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/linearLayout1" 
     android:background="#66ffffff" > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/linearLayout2" > 

     <LinearLayout 
      android:id="@+id/LinearLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/widget_project" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:maxLines="1" 
       android:text="project_name" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:textColor="#ffffff" 
       android:textStyle="bold" /> 



      <TextView 
       android:id="@+id/widget_error" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:maxLines="1" 
       android:text="Error Message comes here" 
       android:textColor="#ff0000" 
       android:textStyle="bold" 
       android:visibility="gone" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/LinearLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="2.25" 
      android:orientation="vertical" > 

      <Button 
       android:id="@+id/widget_button" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/blue_button" 
       android:ellipsize="marquee" 
       android:focusable="true" 
       android:focusableInTouchMode="true" 
       android:marqueeRepeatLimit="marquee_forever" 
       android:maxLines="1" 
       android:scrollHorizontally="true" 
       android:singleLine="true" 
       android:text="start" 
       android:textColor="#ffffff" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 
</RelativeLayout> 

Widget - OnReceive метод

AppWidgetManager manager = AppWidgetManager.getInstance(context); 
ComponentName thisWidget = new ComponentName(context, MainWidget.class); 
RemoteView remoteViews = new RemoteViews(context.getPackageName(), 
       R.layout.main_widget); 
remoteViews.setViewVisibility(R.id.widget_refresh_button, View.GONE); 
remoteViews.setViewVisibility(R.id.widget_loading, View.VISIBLE); 
manager.updateAppWidget(thisWidget, remoteViews); 

вызов этого метода, потому что мой виджет не работает ...

И я не заметил никаких сообщений относительно этой проблемы в Logcat

Пожалуйста, предоставьте мне лучший способ сделать это ...

+0

Я столкнулся с этой проблемой на небольших устройствах, для небольших устройств должна быть разделенная компоновка, если вы упомянете устройства, которые вы используете, это может дать нам подсказку или попробовать другой манекен и простой макет для виджета, чтобы проверить его в 2.2 – user1283633

+1

Я тестировал в avd – Sridhar

ответ

1

После долгих проб и ошибок я нашел ошибку. Я использовал remoteViews.setViewVisibility(R.id.widget_loading, View.VISIBLE); Эта строка не отображает мой виджет. Я удалил все строки setViewVisibility из моего кода. Теперь его показ .....