0
我正在创建一个TextView并为其设置LayoutParams。 但是,当我显示TextView的大小为0设置TextView的宽度
下面是我的代码:
TextView t = new TextView(getBaseContext());
t.setBackgroundResource(R.drawable.roundbox);
t.setText(new String("Hi").toCharArray(), 0, 2);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
lp.bottomMargin = 10;
lp.gravity = Gravity.RIGHT;
t.setLayoutParams(lp);
的roundbox.xml内容是:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp"/>
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp" android:color="#4fa5d5"/>
</shape>
能否请你让我知道什么应该我在LayoutParams构造函数中设置宽度和高度。我设置了一些任意值,但是我希望TextView的大小基于文本的大小。