首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android -在代码中应用9补丁

Android -在代码中应用9补丁
EN

Stack Overflow用户
提问于 2012-02-20 03:09:24
回答 1查看 832关注 0票数 1

如何将9补丁应用于Android TextView IN代码?

你可能会问,为什么?因为我需要动态设置控件的数量。

我试着做一些类似的事情,但是没有效果:

(我在代码中的9补丁"notif_bubble_white.9.png“是R.drawable.notif_bubble_white)

代码语言:javascript
复制
  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被定义为:

代码语言:javascript
复制
  LinearLayout.LayoutParams lpL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
        LinearLayout.LayoutParams.WRAP_CONTENT); 
EN

回答 1

Stack Overflow用户

发布于 2012-04-22 11:03:13

您可以一次创建所有控件,并使用control.setVisibility(View.GONE)将其隐藏,直到需要,或者,如果控件的数量未知,则可以像this question中所述那样膨胀布局文件。

从引用的问题中复制的代码( Cedric,或Pentium10,idk,假设控制是一个按钮):

button.xml:

代码语言:javascript
复制
<Button
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

充气按钮:

代码语言:javascript
复制
button = (Button) getLayoutInflater().inflate(R.layout.button, null);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9352285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档