2016-10-23 2 views
0

certains où je vais mal et incapable de le réparer moi-même.Comment aligner la vue de texte avec tablerow

ici va, je crée 4 vues de texte et de l'ajouter à la ligne du tableau dans le temps d'exécution. La largeur de la vue de texte est égale à la colonne d'en-tête wdith et la hauteur de la vue de texte est fixée à 40dip. tout semble bon quand les données sont dans la largeur de la vue de texte. mais tronque lorsque les données sont sur la largeur de la vue de texte.

La vue de texte ne s'aligne pas sur son tablerow (parent) comme dans la capture d'écran.

https://i.stack.imgur.com/USFlb.jpg

suggestions seraient appréciés.

mon code:

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; 

} 

Répondre

-1

alors essayez d'enlever le padding_top pour et voir. J'espère que ça aide

+0

Non, le rembourrage que j'utilise est pour gauche et droite. public void setPadding (int à gauche, int en haut, int à droite, en bas) – Swetha