Widget在不同手机上不兼容

发布于 2025-01-02 09:27:53 字数 2411 浏览 1 评论 0原文

我创建了一个显示 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一世旳自豪 2025-01-09 09:27:53

为什么不将整个布局 xml 代码放在 linera 布局中,方向为 Vertical ?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

Your Current Layout xml code inside....

</LinearLayout>

尝试一下..我认为它应该可以正常工作!

why dont you put the entire layout xml code in a linera layout with orientation as Vertical ?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

Your Current Layout xml code inside....

</LinearLayout>

try it out..i think it should work fine!!

月下凄凉 2025-01-09 09:27:53

ImageView的布局是fill_parent。也许您还需要在那里指定尺寸。

The layout of the ImageView is fill_parent. Probably you need to specify a size there as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文