Версия XML (с использованием TableLayout, трюк работает и для LinearLayout, если вы предпочитаете это):
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<!-- Set the width to 0dp and set layout_weight=1! on both Views-->
<TextView
android:text="This is text1, its pretty long but that shouldn't be a problem"
android:layout_marginLeft="1px"
android:background="#ff0000"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView
android:text="Shorter"
android:background="#00ff00"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
И используя код, на этот раз с LinearLayout:
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
TextView t1 = new TextView(this);
t1.setBackgroundColor(Color.BLUE);
t1.setText("This is text1, its pretty long but that shouldn't be a problem");
TextView t2 = new TextView(this);
t2.setBackgroundColor(Color.GRAY);
t2.setText("Shorter");
layout.addView(t1, new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
layout.addView(t2, new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));