I know that you can use weight parameters for linear layout in order to make two fields align nicely. What I want to do is I want to make sure that left half of the screen is used by one text field and other half is used by other text field (I am talking about width). How to do so?
LinearLayout : 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.
You can't use relative layout directly inside constraint layout. Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.
RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on.
Use a "hidden view", with no height or width, in the center and put the text views on either side. Use parent align to set left and right.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View android:id="@+id/dummy"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_centerInParent="true"/>
<TextView
android:layout_alignRight="@id/dummy"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_alignLeft="@id/dummy"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
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