What i have is a dynamic table layout and add cells by code not by layout , and here is an image for it :
And the problem is that i have made a layout for each textview to be surrounded by a border which work fine with all cells except the fourth one , as you can see from the image it does not fit correctly like the other cells , what is the reason of this?
Here is my xml layout code :
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/back" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/table1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_gravity="right" >
<TableRow
android:id="@+id/tableRow1"
android:gravity="right"
android:layout_gravity="right">
</TableRow>
</TableLayout>
</ScrollView>
</HorizontalScrollView>
</LinearLayout>
And here is my activity code :
public class MyOrder extends Activity{
double width;
double height;
String type="";
double squared;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myorder);
// try{
width=9.0;
height=10.0;
type="zebra";
squared=width*height;
TableLayout ll = (TableLayout) findViewById(R.id.table1);
//ll.setGravity(Gravity.RIGHT);
//title row
TableRow row= new TableRow(this);
TableRow.LayoutParams tr = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT);
row.setLayoutParams(tr);
TextView Typetext = new TextView(this);
Typetext.setTextColor(Color.BLACK);
TextView Widthtext = new TextView(this);
Widthtext.setTextColor(Color.BLACK);
TextView Heighttext = new TextView(this);
Heighttext.setTextColor(Color.BLACK);
TextView Squaredtext = new TextView(this);
Squaredtext.setTextColor(Color.BLACK);
TextView Notestext = new TextView(this);
Notestext.setTextColor(Color.BLACK);
//
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.back2);
Notestext.setText("ملاحظات");
Notestext.setPadding(0, 0, 0, 0);
Notestext.setTextSize((float) 20.0);
Notestext.setBackgroundDrawable(drawable);
//***************************************//
Squaredtext.setText("مربع المساحة");
Squaredtext.setPadding(0, 0, 0, 0);
Squaredtext.setTextSize((float) 20.0);
Squaredtext.setBackgroundDrawable(drawable);
//***************************************//
Heighttext.setText(" الإرتفاع ");
Heighttext.setPadding(0, 0, 0, 0);
Heighttext.setTextSize((float) 20.0);
Heighttext.setBackgroundDrawable(drawable);
//***************************************//
Widthtext.setText(" العرض ");
Widthtext.setPadding(0, 0, 0, 0);
Widthtext.setTextSize((float) 20.0);
Widthtext.setBackgroundDrawable(drawable);
//***************************************//
Typetext.setText(" الصنف ");
Typetext.setPadding(0, 0, 0, 0);
Typetext.setTextSize((float) 20.0);
Typetext.setBackgroundDrawable(drawable);
//*****************************************//
row.addView(Notestext);
row.addView(Squaredtext);
row.addView(Heighttext);
row.addView(Widthtext);
row.addView(Typetext);
TableRow row1= new TableRow(this);
TableRow.LayoutParams tr1 = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT);
row1.setLayoutParams(tr1);
//text fields
TextView Type = new TextView(this);
TextView Width = new TextView(this);
TextView Height = new TextView(this);
TextView Squared = new TextView(this);
EditText Notes = new EditText(this);
//data
Type.setText(type);
Width.setText(width+"");
Height.setText(height+"");
Squared.setText(squared+"");
row1.addView(Notes);
row1.addView(Squared);
row1.addView(Height);
row1.addView(Width);
row1.addView(Type);
ll.addView(row,0);
ll.addView(row1,1);
}
}
And here is the style of each cell : back xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://ift.tt/nIICcg" android:shape="rectangle" >
<solid android:color="#ffffff" />
<stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>
Any help??
No comments:
Post a Comment