在Android活动中….如何仅使用代码而不是XML进行以下 *** 作?
<TextVIEw androID:background="#0000ff" androID:layout_margin="2dip"/>
我还需要文本右对齐…
卡在上面一会儿=(如果有人可以帮忙
谢谢
更新
我尝试了下面的代码
relativeLayout.LayoutParams lp = new relativeLayout.LayoutParams( relativeLayout.LayoutParams.FILL_PARENT, relativeLayout.LayoutParams.FILL_PARENT); //250); lp.setmargins(5,5,5,5);
而我做到了
row.addVIEw(t1, lp);row.addVIEw(t2);row.addVIEw(t3);row.addVIEw(t4);
我也尝试了linearLayout
但由于某种原因t1不再显示.
解决方法:
这是如何编写textVIEw的代码:
mTextVIEw = new TextVIEw(this); mTextVIEw.setGravity(Gravity.CENTER_VERTICAL); mTextVIEw.setText(R.string.instructions); mTextVIEw.setTextcolor(0xFF000000); mTextVIEw.setpadding(20, 8, 8, 20); mTextVIEw.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8); mScroll = new ScrollVIEw(this); mScroll.setScrollbarFadingEnabled(false); mTextPane = new relativeLayout(this); mTextPane.setVisibility(VIEw.GONE); //mScroll.setVisibility(VIEw.GONE); mScroll.addVIEw(mTextVIEw); mTextPane.addVIEw(mScroll); Resources res = getResources(); //Drawable drawable = res.getDrawable(R.drawable.text_pane_feather2); Drawable drawable = res.getDrawable(R.drawable.text); mTextPane.setBackgroundDrawable(drawable); //relativeLayout.LayoutParams lp = new relativeLayout.LayoutParams( 420, 420 ); relativeLayout.LayoutParams lp = new relativeLayout.LayoutParams( relativeLayout.LayoutParams.WRAP_CONTENT, //relativeLayout.LayoutParams.WRAP_CONTENT); 250); lp.setmargins(0,0,0,30); lp.addRule(relativeLayout.CENTER_HORIZONTAL ); lp.addRule(relativeLayout.AliGN_PARENT_BottOM); layout.addVIEw(mTextPane, lp);
总结 以上是内存溢出为你收集整理的android TextView使用代码设置边距和背景全部内容,希望文章能够帮你解决android TextView使用代码设置边距和背景所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)