0
我一直在努力創建Android佈局,我仍然在尋找一個非常可靠的教程,提供有用的示例。Android Widget佈局
目前,我正在嘗試創建一個類似於市場上許多現有Android小部件的小部件。例如,簡單天氣小部件包含小部件右側(圖像旁邊)的溫度以及包含更多信息(如預測)的小部件右側的一般文本。我有下面的代碼,我的圖片無法正確加載。文本也無法加載到小部件上。有人可以幫助指導我,讓我至少可以看到的圖像與一些文字:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:background="@drawable/appwidget_bg"
android:layout_height="fill_parent">
<ImageButton
android:id="@+id/message_button"
android:layout_width="100px"
android:layout_height="wrap_content"
android:src="@drawable/messages"
android:scaleType="fitXY"
/>
<ImageView
android:id="@+id/divider"
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="@drawable/appwidget_divider"
android:layout_alignRight="@+id/message_button"
/>
<TextView
android:id="@+id/current_kw"
android:layout_toRightOf="@+id/divider"
android:layout_width="80px"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#ffffff"
android:typeface="sans"
android:text="TBD"
android:gravity="center_horizontal|center_vertical"
/>
<ImageView
android:id="@+id/divider2"
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="@drawable/appwidget_divider"
android:layout_alignRight="@+id/current_kw"
/>
<TextView
android:id="@+id/temp"
android:layout_toRightOf="@+id/divider2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="10sp"
android:textColor="#ffffff"
android:paddingLeft="1dp"
android:fadingEdgeLength="2dip"
android:text="Temperature"
/>
<TextView
android:id="@+id/estimate_cost"
android:layout_toRightOf="@+id/current_kw"
android:layout_below="@+id/temp"
android:paddingLeft="1dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your estimated cost:"
android:textSize="10sp"
android:gravity="center_horizontal"
android:layout_weight="1.0"
/>
<TextView
android:id="@+id/communitysize"
android:layout_toRightOf="@+id/current_kw"
android:layout_below="@+id/estimate_cost"
android:text="Size of the community: "
android:textSize="10sp"
android:paddingTop="1dp"
android:layout_width="wrap_content"
android:gravity="center_horizontal"
android:layout_height="wrap_content" />
</RelativeLayout>
感謝您的鏈接陽光的教程。這有助於。我已經將我的代碼更新爲現在的工作。只是好奇,你知道爲什麼似乎有一個圍繞我的形象的邊界? –
我應該使用ImageView而不是ImageButton。這解決了我的問題。謝謝! –