2

ボタンのテキストのサイズに問題があります。weightSum を使用するレイアウトがあり、ボタンの幅は親と一致し、高さは 30% です。すべて正常に動作しますが、エミュレータで画面のサイズを変更すると、テキストがまだ小さいです。画面のサイズに応じてテキストのサイズを変更するにはどうすればよいですか? これはxmlです:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="100" >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_weight="30" />

</LinearLayout>

これを自動的に行う方法はありますか?

4

4 に答える 4

3

ボタンのテキストサイズの単位として sp を使用する

<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button"
android:textSize="20sp"
android:layout_weight="30" />

これで問題が解決しない場合は、次のようなフォルダーを作成します

1) レイアウト 2) レイアウト-小 3) レイアウト-大 4) レイアウト-x大

Nikhilが提案したように、これと一緒にこれを考慮してください

上記のフォルダーと同じように、画面の種類ごとに異なる値のフォルダーを作成できます

1) 値 2) 値 - 小 3) 値 - 大 ...

それぞれに dimens.xml という xml ファイルを作成し、以下のように dimen リソースを参照してボタンの textSize を指定します。

<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button"
android:textSize="@dimen/small_font"
android:layout_weight="30" />

これにより、画面サイズに応じてフォントサイズが設定されます

これがあなたに役立つことを願っています

于 2012-05-15T07:49:59.277 に答える
1

さまざまな画面の場合、Android にはさまざまなレイアウトがあります。すべての画面の UI を作成したい場合は、レイアウト用に 4 つのフォルダーを作成する必要があります。

1) layout
2) layout-small
3) layout-large
4) layout-xlarge

詳細については、次のリンクを参照してください。

http://developer.android.com/guide/practices/screens_support.html

于 2012-05-15T07:21:24.957 に答える
1

ボタンの XML に追加する場合:

<Button
    android:id="@+id/button1"
    android:text="click me"
    android:textSize="22dp" />

これでうまくいくはずです。

テキストサイズを動的に変更したい場合は、画面サイズを取得してから textSize を設定する必要がありますbutton.setTextSize(size);

于 2012-05-15T07:15:08.437 に答える
-3
<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Button"
    android:textSize="22dp"
    android:layout_weight="30" />
于 2012-05-15T07:23:40.090 に答える