Try below code:-
LinearLayout table_date =(LinearLayout) findViewById(R.id.table_data);
TableLayout tlt = new TableLayout(Scheduler.this);
for (int i = 0; i < 25; i++)
{
showTime(i,tlt);
}
table_date.addView(tlt);
TableLayout tl = new TableLayout(Scheduler.this);
for (int i = 0; i < 24; i++)
{
TableRow tr = new TableRow(Scheduler.this);
TextView tv = new TextView(Scheduler.this);
tv.setTextColor(getResources().getColor(R.color.black));
tv.setTextSize(9);
tv.setPadding(10, 0, 0, 0);
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setTag("personal::::"+i);
tv.setOnClickListener(click);
tv.setHeight(50);
tv.setWidth((int)10);
tr.setBackgroundResource(R.drawable.row_bg);
tr.addView(tv);
tl.addView(tr, new TableRow.LayoutParams((int)10, 50));
}
table_date.addView(tl);
showTime function
private void showTime(int i ,TableLayout tlt)
{
// TODO Auto-generated method stub
TableRow tr = new TableRow(Scheduler.this);
TextView tv = new TextView(Scheduler.this);
for(int i1=0 ; i1<10 ; i1++)
{
tv.setText((i-1)+".00 AM");
tv.setTextColor(getResources().getColor(R.color.white));
tv.setTextSize(8);
tv.setHeight(50);
tv.setWidth(60);
tv.setPadding(5, 0, 0, 0);
tv.setGravity(Gravity.CENTER_VERTICAL);
tr.addView(tv);
}
tr.setBackgroundResource(R.drawable.row_time_bg);
tlt.addView(tr);
}
xml
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/color" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/table_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9" >
<LinearLayout
android:id="@+id/table_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
above code works fine for me.