ramesh
ramesh

Reputation: 4082

Android align button and text in a table layout

I am trying to create a table view with a text view and a button in android. Below is my sample code ( work in progress ). As I am very new to android please help me how to arrange the text view and the button as in the image. Now I am getting button and text view. But its weird.

My Code

TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);          
for (int i = 0; i<30; i++) 
{

 TableRow row = new TableRow(this);
 row.setBackgroundColor(Color.DKGRAY);
 TextView tv = new TextView(this);
 Button btn=new Button(this);

 tv.setTextAppearance(getApplicationContext(), R.style.maxWid);
 tv.setText("Sample Text Here");

 row.addView(tv);
 btn.setText("Approves");
 row.addView(btn);
 table.addView(row);

 }

Style.xml

<style name="maxWid">
    <item name="android:textStyle">bold|italic</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:layout_width">fill_parent</item>
</style>

main_layout.xml

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical"
    android:layout_weight="1">

    <TableLayout  
    android:id="@+id/tableLayout_1"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:shrinkColumns="*"  
    android:stretchColumns="*"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"

    >  

    </TableLayout>  

</ScrollView>

Expected format enter image description here

Fighting with this since 1 day.. Please help Thanks in advance!

Upvotes: 0

Views: 569

Answers (1)

d3m0li5h3r
d3m0li5h3r

Reputation: 1967

what you can do here is create a layout xml using RelativeLayout and then add that into your TableRow.

Upvotes: 1

Related Questions