2012-09-24 91 views
0
了minHeight我

已经宣布使用如何修复的AppWidgetProvider的声明被忽略minwidth和

 <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> 
在res/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> 

我是一个的AppWidgetProvider在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">