2012-09-24 3 views
0

Я объявил AppWidgetProvider используяКак исправить декларацию AppWidgetProvider, которая пренебрегая MinWidth и MinHeight

 <receiver android:name="uk.co.bmc.rad.widgets.NearestOpenCragWidgetProvider" android:exported="false"> 
      <intent-filter> 
       <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
      </intent-filter> 
      <meta-data android:name="android.appwidget.provider" 
        android:resource="@xml/nearest_open_crag_widget_info" /> 
     </receiver> 

в Рез/XML я добавил nearest_open_crag_Widget_info.xml содержащий

<?xml version="1.0" encoding="utf-8"?> 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" > 
    android:minWidth="486dp" 
    android:minHeight="144dp" 
    android:updatePeriodMillis="86400000" 
    android:initialLayout="@layout/nearest_open_crag_widget" 
    android:resizeMode="none"> 
</appwidget-provider> 

Я запуская это в эмуляторе Eclipse и независимо от того, какие размеры я укажу для minWidth и minHeight, виджет добавляется с теми же размерами.

Как вы можете видеть в нижней части экрана здесь: screenshot


В случае это проблема с раскладкой я включу его здесь. Там уже три RelativeLayouts, которые я (в надежде быть) скрытие или раскрывающие в зависимости от состояния

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="@dimen/widget_margin" 
    android:background="#525252" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="35dp" 
     android:background="@color/bmc_red" 
     android:gravity="center" > 

     <TextView 
      android:id="@+id/widget_title" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="center|fill_horizontal" 
      android:gravity="center|center_horizontal" 
      android:text="@string/the_nearest_open_crag_is_" 
      android:textColor="@android:color/white" 
      android:textSize="20dp" /> 
    </RelativeLayout> 

    <ProgressBar 
     android:id="@+id/nearest_crag_loading_progress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:indeterminate="true" /> 

    <RelativeLayout 
     android:id="@+id/nearest_crag_loading_error_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:visibility="gone" > 

     <ImageView 
      android:id="@+id/nearest_crag_error_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:contentDescription="@string/error_image_content_description" 
      android:src="@android:drawable/ic_dialog_alert" /> 

     <TextView 
      android:id="@+id/nearest_crag_loading_error" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/nearest_crag_error_image" 
      android:gravity="center|center_vertical" 
      android:text="@string/ah_no_error_message_crikey_" > 
     </TextView> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/nearest_open_crag_details_wrapper" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:visibility="gone" > 

     <TextView 
      android:id="@+id/name_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/crag_list_spacer" 
      android:singleLine="true" 
      android:text="@string/list_view_name_string" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <TextView 
      android:id="@+id/distance_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@id/name_text" 
      android:layout_marginLeft="@dimen/crag_list_spacer" 
      android:layout_marginRight="@dimen/crag_list_spacer" 
      android:singleLine="true" 
      android:text="@string/list_view_distance_string" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/description_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/distance_text" 
      android:layout_marginLeft="@dimen/crag_list_spacer" 
      android:layout_marginRight="@dimen/crag_list_spacer" 
      android:ellipsize="end" 
      android:singleLine="true" 
      android:text="@string/crag_description" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <Button 
      android:id="@+id/nearest_crag_btn_details" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/description_text" 
      android:layout_below="@+id/description_text" 
      android:layout_marginTop="10dp" 
      android:clickable="true" 
      android:text="@string/open_details" /> 
    </RelativeLayout> 

</LinearLayout> 

Большое спасибо заранее

+0

Возможно, не решение проблемы, но почему вы используете 3 RelativeLayouts? Только один может быть лучше –

ответ

0

Он не игнорирует ваши настройки

читать здесь http://developer.android.com/guide/practices/ui_guidelines/widget_design.html

Если в вашем виджетах с девятью патчами есть встроенное содержимое, вы должны добавить в minWidth и minHeight соответственно.

+0

На моем макете нет фонового девяти патча и независимо от того, что minWidth и minHeight я указываю, что виджет отображается на скриншоте. Итак, minWidth и minHeight игнорируются или что-то еще происходит? –

0

Вы должны применить тот же MinHeight или MinWidth для детей элемента (выглядит отсталым, не так ли?)

Настройки в appwidget-провайдера работает, если вы настраиваете одинаковые настройки для детей, в моем вашем случае это:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="@dimen/widget_margin" 
    android:background="#525252" 
    android:minWidth="486dp" 
    android:minHeight="144dp"> 
Смежные вопросы