-1

ボタンの中央にテキストを表示しようとしていますが、そのようにテキストがボタンに完全に収まりません

ここに画像の説明を入力

ここにVとWを表示しようとしていますが、スペースもありますが、収まりません。助けてください

スタイルのテキストはこのようなものです

<style name="textstyle">
        <item name="android:textSize">15sp</item>
        <item name="android:gravity">center</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#000000</item>
    </style>

ボタンのサイズは実行時に決定されます

box = new Button(context);
        box.setTextAppearance(context, R.style.input_box_textstyle);
        Drawable image = context.getResources().getDrawable(R.drawable.inputbox); 
        box.setBackgroundDrawable(image);
.
.
.
 if(size <= n)
         {

            Log.v("textsize..", width+"");

             p = new LinearLayout.LayoutParams(width, height);
         }
         else
         {
             p = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 60);
             p.weight = 1;
         }

        box.setLayoutParams(p);


        isSet = false;
4

2 に答える 2

1

を設定して問題を解決する

box.setIncludeFontPadding(false);
        box.setPadding(0, 0, 0, 0);
于 2013-10-07T19:44:02.763 に答える
0

これがあなたのxmlでなければならないことを願っています

<LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:baselineAligned="false"
        android:layout_below="@id/imagetitle"
        android:orientation="horizontal">
     <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="V" android:id="@+id/previous" />
      <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="W" android:id="@+id/next" />
    </LinearLayout>
于 2013-10-07T18:29:00.973 に答える