<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left"/> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" /> </LinearLayout> </LinearLayout>
I'm trying to create a layout with two columns, with one textview on the left side and the other on the right side. However, the textviews are still all on the left side.
You just put a separate LinearLayout with android:orientation="horizontal" around each pair of buttons. Then the parent LinearLayaout should have android:orientation="vertical" and the weightsum should be in each horizontal LinearLayout.
Relativelayout is more effective than Linearlayout. From here: It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.
Android Layout TypesLinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.
You should use android:layout_weight
attribute. Here is an example:
<LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/textView1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="Street" android:layout_gravity="left" android:background="#88FF0000"/> <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="456546546" android:layout_gravity="right" android:background="#8800FF00"/> </LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With