2012-02-08 2 views
0

Я создал виджет. Он показывает детали Wi-Fi, такие как имя сети, Ip и MAC-адрес. Но я не могу дать фиксированный размер для текста, который я использую в виджетах. Если на экране меняется размер текста, также необходимо отрегулировать его. Как мы можем это сделать?Android-виджет в разных телефонах

Мой XML-файл приведен ниже.

<?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

Добавьте код, и показать, что вы уже пробовали. – nhaarman

+0

добавил мой макет – Kamalone

+0

Когда вы ссылаетесь на фиксированный размер, вы имеете в виду размер шрифта или пространство, доступное в виджетах? –

ответ

1

Вы должны использовать sp для вашего TextSize:

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

Read more.

Смежные вопросы