使用setVisibility
在背景中隱藏具有自己樣式的佈局。 像這樣:
public static void changeWidgetState(RemoteViews remoteView, int state){
switch (state){
case 0:{
remoteView.setViewVisibility(R.id.widgetLayout1, View.VISIBLE);
remoteView.setViewVisibility(R.id.widgetLayout2, View.GONE);
} break;
case 1:{
remoteView.setViewVisibility(R.id.widgetLayout1, View.GONE);
remoteView.setViewVisibility(R.id.widgetLayout2, View.VISIBLE);
} break;
...
default:
}
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widgetLayout0"
android:layout_width="150dip"
android:layout_height="wrap_content"
>
<!--Normal Theme Black Text -->
<RelativeLayout
android:id="@+id/widgetLayout1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
style="@style/WidgetBackgroundNormal"
/>
<!--Yellow Theme Black Text -->
<RelativeLayout
android:id="@+id/widgetLayout2"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
style="@style/WidgetBackgroundYellow"
/>
...
<LinearLayout
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:paddingTop="7dip"
>
<TextView
android:id="@+id/widget_server_name"
style="@style/Text.DefinitionWhite"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="10dip"
/>
....
</LinearLayout>
</RelativeLayout>
我不明白這比僅僅選擇一個佈局文件或另一個更好...這是同一件事,但在一個數據文件中。 – 2011-02-18 22:08:36
哦,你會如何做到這一點,你能舉個例子嗎? – 2011-02-19 00:36:43