Widget在不同手机上不兼容
我创建了一个显示 WiFi 状态和信息的小部件。我创建并测试了一部 Android 版本 4.0 的手机。当我用其他版本较低的手机进行测试时,小部件中使用的文本变得很小并且分散了我在其中使用的所有组件。我使用的布局 xml 如下所示。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/wifi_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<TextView
android:id="@+id/wifi_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="64dp"
android:layout_marginTop="13dp"
android:textSize="11dip" />
<TextView
android:id="@+id/wifi_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="64dp"
android:layout_marginTop="13dp"
android:textColor="@android:color/white"
android:textSize="11dip" />
<TextView
android:id="@+id/wifi_notconnected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="64dp"
android:layout_marginTop="30dp"
android:textColor="@android:color/white"
android:textSize="7dp" />
<ImageView
android:id="@+id/wifi_signal_strength"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/wifi_circle"
android:layout_width="66dp"
android:layout_height="76dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="3dp"
android:background="@drawable/onpress_wifi_icon_circle_null"
android:src="@drawable/toggle" />
<ImageView
android:id="@+id/wifi_square"
android:layout_width="83dp"
android:layout_height="55dp"
android:layout_alignRight="@+id/wifi_circle"
android:layout_marginLeft="60dp"
android:layout_marginTop="8dp"
android:background="@drawable/onpress_network_info_squre_null"
android:src="@drawable/togglenetwork" />
</FrameLayout>
I created a Widget which shows the WiFi status and information. I created and tested a phone having android version 4.0. While i am testing it with the other phones which is lower in version the text used in the widget are becoming small and scattered all the components i used in it. The layout xml i used is given below.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/wifi_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<TextView
android:id="@+id/wifi_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="64dp"
android:layout_marginTop="13dp"
android:textSize="11dip" />
<TextView
android:id="@+id/wifi_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="64dp"
android:layout_marginTop="13dp"
android:textColor="@android:color/white"
android:textSize="11dip" />
<TextView
android:id="@+id/wifi_notconnected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginLeft="64dp"
android:layout_marginTop="30dp"
android:textColor="@android:color/white"
android:textSize="7dp" />
<ImageView
android:id="@+id/wifi_signal_strength"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/wifi_circle"
android:layout_width="66dp"
android:layout_height="76dp"
android:layout_marginLeft="1dp"
android:layout_marginTop="3dp"
android:background="@drawable/onpress_wifi_icon_circle_null"
android:src="@drawable/toggle" />
<ImageView
android:id="@+id/wifi_square"
android:layout_width="83dp"
android:layout_height="55dp"
android:layout_alignRight="@+id/wifi_circle"
android:layout_marginLeft="60dp"
android:layout_marginTop="8dp"
android:background="@drawable/onpress_network_info_squre_null"
android:src="@drawable/togglenetwork" />
</FrameLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不将整个布局 xml 代码放在 linera 布局中,方向为 Vertical ?
尝试一下..我认为它应该可以正常工作!
why dont you put the entire layout xml code in a linera layout with orientation as Vertical ?
try it out..i think it should work fine!!
ImageView的布局是fill_parent。也许您还需要在那里指定尺寸。
The layout of the ImageView is fill_parent. Probably you need to specify a size there as well.