0
私は間違っていて、自分で修正できない部分もあります。tablerowとテキストビューを整列する方法
ここでは、4つのテキストビューを作成し、それを実行時にテーブル行に追加します。 テキストビューの幅はヘッダ列wdithと等しく、テキストビューの高さは40dipに固定されています。データがテキストビューの幅内にあるときは、すべてが良好に見えます。データがテキストビューの幅を超えている場合は切り捨てられます。
スクリーンショットのように、Textviewがtablerow(親)に整列していません。
https://i.stack.imgur.com/USFlb.jpg
任意の提案をいただければ幸いです。
私のコード:
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;
}
いいえ、私が使用しているパッドは左右です。 パブリックvoid setPadding(int left、int top、int right、int bottom) – Swetha