本文介绍了如何设置TextView的在中心动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的code,我想设置在中心文本视图看到这code请告诉我如何设置
我尝试这个编code,但日期文本视图不来CENTER请告诉变更
的LinearLayout [112 =新的LinearLayout(CTX);
LP3的LayoutParams =新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ll2.setLayoutParams(LP3);
ll2.setOrientation(LinearLayout.VERTICAL); LP2的LayoutParams = NULL;
的LinearLayout器114 =新的LinearLayout(CTX);
LP2 =新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); TextView中TV2 =新的TextView(CTX);
LP2 =新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT); tv2.setLayoutParams(LP2);
tv2.setText(MESSAGE);
tv2.setBackgroundResource(R.drawable.rec);
tv2.setTextSize(14);
tv2.setTextColor(Color.parseColor(#5A3084));
如果(SM = NULL&放大器;!&安培; sm.message!= NULL)
tv2.setText(sm.message.toString());
tv2.setGravity(Gravity.LEFT);
tv2.setPadding(10,0,10,0); TextView的TV0 =新的TextView(CTX);
LP2 =新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
tv0.setLayoutParams(LP2);
tv0.setText(Alertdate:);
tv0.setBackgroundResource(R.drawable.rec1);
tv0.setTextColor(Color.parseColor(#38385E));
tv0.setGravity(Gravity.CENTER_VERTICAL);
tv0.setTextSize(12);
如果(SM = NULL&放大器;!&安培;!sm.alertdate = NULL) tv0.setText(sm.alertdate +);
解决方案
我解决这个code及其工作
的LinearLayout [112 =新的LinearLayout(CTX);
LP3的LayoutParams =新的LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
ll2.setLayoutParams(LP3);
ll2.setOrientation(LinearLayout.VERTICAL); LP2的LayoutParams = NULL;
的LinearLayout器114 =新的LinearLayout(CTX);
LP2 =新的LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); TextView中TV2 =新的TextView(CTX);
LP2 =新的LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.FILL_PARENT); tv2.setLayoutParams(LP2);
tv2.setText(MESSAGE);
tv2.setBackgroundResource(R.drawable.rec3);
tv2.setTextSize(14);
// tv2.setTextColor(Color.parseColor(#FFFFFF));
tv2.setTextColor(Color.parseColor(#5A3084));
字体typface = Typeface.createFromAsset(ctx.getAssets()
字体/的Roboto-Regular.ttf); tv2.setTypeface(typface);
如果(SM = NULL&放大器;!&安培; sm.message!= NULL)
tv2.setText(sm.message.toString());
tv2.setGravity(Gravity.LEFT);
tv2.setPadding(15,8,10,8); TextView的TV0 =新的TextView(CTX);
LinearLayout.LayoutParams LP21 =新LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp21.gravity = Gravity.CENTER; tv0.setLayoutParams(LP21);
tv0.setText(Alertdate:);
tv0.setBackgroundResource(R.drawable.rec1);
tv0.setTextColor(Color.parseColor(#FFFFFF)); tv0.setTextSize(12);
如果(SM = NULL&放大器;!&安培;!sm.alertdate = NULL)
tv0.setGravity(Gravity.CENTER_VERTICAL);
dataF = sm.alertdate;
outdat = changeDateFormat(dataF);
tv0.setText(outdat); // tv0.setText(sm.alertdate +); tv0.setPadding(10,0,10,0); // tv0.setBackgroundResource(R.drawable.custom);
TextView的TV1 =新的TextView(CTX);
LP2 =新的LayoutParams(pixelCount(10),pixelCount(10));
tv1.setLayoutParams(LP2);
In my code ,i want to set the text view in CENTER see this code pls ,tell me how to set
i try ed this code but the date text view is not coming CENTER pls tell the changes
LinearLayout ll2=new LinearLayout(ctx);
LayoutParams lp3=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ll2.setLayoutParams(lp3);
ll2.setOrientation(LinearLayout.VERTICAL);
LayoutParams lp2=null;
LinearLayout ll4=new LinearLayout(ctx);
lp2=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
TextView tv2=new TextView(ctx);
lp2=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.FILL_PARENT);
tv2.setLayoutParams(lp2);
tv2.setText("MESSAGE");
tv2.setBackgroundResource(R.drawable.rec);
tv2.setTextSize(14);
tv2.setTextColor(Color.parseColor("#5A3084"));
if(sm!=null && sm.message!=null)
tv2.setText(sm.message.toString());
tv2.setGravity(Gravity.LEFT);
tv2.setPadding(10, 0, 10, 0);
TextView tv0=new TextView(ctx);
lp2=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
tv0.setLayoutParams(lp2);
tv0.setText("Alertdate :");
tv0.setBackgroundResource(R.drawable.rec1);
tv0.setTextColor(Color.parseColor("#38385E"));
tv0.setGravity(Gravity.CENTER_VERTICAL);
tv0.setTextSize(12);
if(sm!=null && sm.alertdate!=null)
tv0.setText(sm.alertdate+"");
解决方案
i fix this code its working
LinearLayout ll2 = new LinearLayout(ctx);
LayoutParams lp3 = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
ll2.setLayoutParams(lp3);
ll2.setOrientation(LinearLayout.VERTICAL);
LayoutParams lp2 = null;
LinearLayout ll4 = new LinearLayout(ctx);
lp2 = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
TextView tv2 = new TextView(ctx);
lp2 = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.FILL_PARENT);
tv2.setLayoutParams(lp2);
tv2.setText("MESSAGE");
tv2.setBackgroundResource(R.drawable.rec3);
tv2.setTextSize(14);
// tv2.setTextColor(Color.parseColor("#ffffff"));
tv2.setTextColor(Color.parseColor("#5A3084"));
Typeface typface = Typeface.createFromAsset(ctx.getAssets(),
"fonts/Roboto-Regular.ttf");
tv2.setTypeface(typface);
if (sm != null && sm.message != null)
tv2.setText(sm.message.toString());
tv2.setGravity(Gravity.LEFT);
tv2.setPadding(15, 8, 10, 8);
TextView tv0 = new TextView(ctx);
LinearLayout.LayoutParams lp21 = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp21.gravity = Gravity.CENTER;
tv0.setLayoutParams(lp21);
tv0.setText("Alertdate :");
tv0.setBackgroundResource(R.drawable.rec1);
tv0.setTextColor(Color.parseColor("#ffffff"));
tv0.setTextSize(12);
if (sm != null && sm.alertdate != null)
tv0.setGravity(Gravity.CENTER_VERTICAL);
dataF = sm.alertdate;
outdat = changeDateFormat(dataF);
tv0.setText(outdat);
// tv0.setText(sm.alertdate+"");
tv0.setPadding(10, 0, 10, 0);
// tv0.setBackgroundResource(R.drawable.custom);
TextView tv1 = new TextView(ctx);
lp2 = new LayoutParams(pixelCount(10), pixelCount(10));
tv1.setLayoutParams(lp2);
这篇关于如何设置TextView的在中心动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!