2012-02-08 6 views
0

J'ai créé un widget. Il montre les détails du WiFi, comme le nom du réseau, IP et l'adresse MAC. Mais je ne suis pas capable de donner une taille fixe pour le texte que j'utilise dans le widget. Si l'écran change, la taille du texte doit également s'ajuster avec cela. Comment pouvons-nous faire cela?Widget Android dans différents téléphones

Mon fichier XML est donné ci-dessous.

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="@dimen/widget_margin" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/wifi_background" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/padding_left" 
    android:paddingTop="22dp" 
    android:orientation="vertical" 
    > 
<FrameLayout android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 

    <TextView 
    android:id="@+id/wifi_status" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="12dp" 
    /> 

<TextView 
    android:id="@+id/wifi_on" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@android:color/white" 
    android:textSize="12dp" 
    /> 

</FrameLayout> 

<TextView 
    android:id="@+id/wifi_notconnected" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@android:color/white" 
    android:textSize="7dp" 
    /> 
</LinearLayout> 

<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="@dimen/circle_width" 
    android:layout_height="@dimen/circle_hieght" 
    android:layout_marginLeft="2dp" 
    android:layout_gravity="center_vertical" 
    android:background="@drawable/onpress_wifi_icon_circle_null" 
    android:src="@drawable/toggle" /> 

<ImageView 
    android:id="@+id/wifi_square" 
    android:layout_width="@dimen/square_width" 
    android:layout_height="@dimen/square_hieght" 
    android:layout_marginTop="8dp" 
    android:layout_gravity="right|top" 
    android:background="@drawable/onpress_network_info_squre_null" 
    android:src="@drawable/togglenetwork" /> 

</FrameLayout> 
+0

Ajouter un code, et montrer ce que vous avez essayé. – nhaarman

+0

a ajouté ma mise en page – Kamalone

+0

Lorsque vous faites référence à la taille fixe, voulez-vous dire la taille de la police ou l'espace disponible dans le widget? –

Répondre

1

Vous devez utiliser sp pour votre TextSize:

<TextView 
    android:id="@+id/wifi_status" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="12sp" 
/> 

Read more.

Questions connexes