Android 如何将文本视图与tablerow对齐
有些地方我出了问题,自己也无法解决 接下来,我将创建4个文本视图,并在运行时将其添加到表行中。 文本视图的宽度等于标题列wdith,文本视图的高度固定为40dip。当数据在textview的宽度范围内时,一切看起来都很好。但当数据超过textview的宽度时会截断 Textview未与屏幕截图中的tablerow(父级)对齐 如有任何建议,将不胜感激 我的代码:Android 如何将文本视图与tablerow对齐,android,textview,android-tablelayout,Android,Textview,Android Tablelayout,有些地方我出了问题,自己也无法解决 接下来,我将创建4个文本视图,并在运行时将其添加到表行中。 文本视图的宽度等于标题列wdith,文本视图的高度固定为40dip。当数据在textview的宽度范围内时,一切看起来都很好。但当数据超过textview的宽度时会截断 Textview未与屏幕截图中的tablerow(父级)对齐 如有任何建议,将不胜感激 我的代码: public void initi() { Bundle bundle = getArguments(); in
public void initi() {
Bundle bundle = getArguments();
investmentType = bundle.getString("TYPE");
final TableLayout stk = (TableLayout) getActivity().findViewById(R.id.table_main);
TableRow tbrow = new TableRow(getActivity());
TextView textView1 = (TextView) getActivity().findViewById(R.id.MonthName);
tbrow.addView(getTextView(getMonthName(0), textView1.getMeasuredWidthAndState(), 0.5f,0));
TextView textView2 = (TextView) getActivity().findViewById(R.id.Opening);
tbrow.addView(getTextView(formatValue(Double.parseDouble(principal)), textView2.getMeasuredWidthAndState(), 0.90f,0));
String initialMaturityValue = calculateMaturity(principal);
String initialInterestEarned = interestEarned(initialMaturityValue, principal);
TextView textView3 = (TextView) getActivity().findViewById(R.id.InterestE);
tbrow.addView(getTextView(initialInterestEarned, textView3.getMeasuredWidthAndState(), 0.70f,0));
TextView textView4 = (TextView) getActivity().findViewById(R.id.closing);
tbrow.addView(getTextView(initialMaturityValue, textView4.getMeasuredWidthAndState(), 0.90f,0));
stk.addView(tbrow);
String LoopMaturityValue = "";
for (int i = 1; i < duration; i++) {
tbrow = new TableRow(getActivity());
LoopMaturityValue = calculateMaturity(initialMaturityValue);
textView1 = (TextView) getActivity().findViewById(R.id.MonthName);
tbrow.addView(getTextView(getMonthName(i), textView1.getMeasuredWidthAndState(), 0.5f,i));
textView2 = (TextView) getActivity().findViewById(R.id.Opening);
tbrow.addView(getTextView(initialMaturityValue, textView2.getMeasuredWidthAndState(), 0.90f,i));
textView3 = (TextView) getActivity().findViewById(R.id.InterestE);
tbrow.addView(getTextView(interestEarned(LoopMaturityValue, initialMaturityValue), textView3.getMeasuredWidthAndState(), 0.70f,i));
textView4 = (TextView) getActivity().findViewById(R.id.closing);
tbrow.addView(getTextView(LoopMaturityValue, textView4.getMeasuredWidthAndState(), 0.90f,i));
initialMaturityValue = LoopMaturityValue;
stk.addView(tbrow);
}
}
private TextView getTextView(String value, int width, float weight,int i) {
textView = new TextView(getActivity());
textView.setText(value);
// textView.setTextColor(getResources().getColor(R.color.Black));
TableRow.LayoutParams params = new TableRow.LayoutParams(width, (int) dipToPixels(getActivity(),40), weight);
textView.setLayoutParams(params);
textView.setGravity(Gravity.CENTER);
textView.setPadding(3,0,3,0);
if (i % 2 == 0)
textView.setBackground(getActivity().getResources().getDrawable(R.drawable.back));
else
textView.setBackground(getActivity().getResources().getDrawable(R.drawable.border));
return textView;
}
public void initi(){
Bundle=getArguments();
investmentType=bundle.getString(“类型”);
final TableLayout stk=(TableLayout)getActivity().findviewbyd(R.id.table_main);
TableRow tbrow=新TableRow(getActivity());
TextView textView1=(TextView)getActivity().findViewById(R.id.MonthName);
addView(getTextView(getMonthName(0),textView1.getMeasuredWidthAndState(),0.5f,0));
TextView textView2=(TextView)getActivity().findViewById(R.id.Opening);
addView(getTextView(formatValue(Double.parseDouble(principal)),textView2.getMeasuredWidthAndState(),0.90f,0));
字符串InitialThurityValue=calculateMaturity(主体);
字符串initialInterestArned=InterestArned(初始到期日值,本金);
TextView textView3=(TextView)getActivity().findViewById(R.id.interest);
addView(getTextView(initialInterestEarned,textView3.getMeasuredWidthAndState(),0.70f,0));
TextView textView4=(TextView)getActivity().findViewById(R.id.closing);
addView(getTextView(InitialThurityValue,textView4.getMeasuredWidthAndState(),0.90f,0));
stk.addView(tbrow);
字符串LoopThurityValue=“”;
for(int i=1;i
因此,尝试移除顶部的填充物,然后查看。希望能有所帮助不,我使用的填充物是左和右。公共void setPadding(int left、int top、int right、int bottom)