如何将9补丁应用于Android TextView IN代码?
你可能会问,为什么?因为我需要动态设置控件的数量。
我试着做一些类似的事情,但是没有效果:
(我在代码中的9补丁"notif_bubble_white.9.png“是R.drawable.notif_bubble_white)
tv = new TextView(this);
tv.setText("Test Message");
tv.setLayoutParams(lpL);
tv.setPadding(0, 0, paddingValue, 0);
CustomFonts.ApplyFont_Custom1(tv, context);
tv.setBackgroundResource(R.drawable.notif_bubble_white);
// tv.setTextColor(TxtColFromCl);
layout.addView(tv); 其中lpL被定义为:
LinearLayout.LayoutParams lpL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT); 发布于 2012-04-22 11:03:13
您可以一次创建所有控件,并使用control.setVisibility(View.GONE)将其隐藏,直到需要,或者,如果控件的数量未知,则可以像this question中所述那样膨胀布局文件。
从引用的问题中复制的代码( Cedric,或Pentium10,idk,假设控制是一个按钮):
button.xml:
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />充气按钮:
button = (Button) getLayoutInflater().inflate(R.layout.button, null);https://stackoverflow.com/questions/9352285
复制相似问题