Reputation: 16469
I am having trouble getting my TextView
and RadioGroup
in the right position.
I want the TextView
to have its own row and the RadioGroup
to have its own as well. Perhaps also make it easily adjustable so that I can change the spacing between the two.
The TextView
and RadioGroup
are currently on top of each other.
xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/dueDateSection"
android:id="@+id/relativeLayout2"
android:paddingBottom="@dimen/activity_edit_item_layout_vertical_margin"
android:paddingTop="@dimen/activity_edit_item_layout_vertical_margin"
android:gravity="center_vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tvPriorityLabel"
android:textSize="22sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:layout_alignTop="@id/priorityChoice"/>
<RadioGroup
android:id="@+id/priorityChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<RadioButton
android:id="@+id/lowPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/priorityLow"/>
<RadioButton
android:id="@+id/medPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/priorityMedium" />
<RadioButton
android:id="@+id/highPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/priorityHigh" />
</RadioGroup>
</RelativeLayout>
Upvotes: 0
Views: 695
Reputation: 4182
You can try this... take all in One Row
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout2"
android:gravity="center_vertical"
android:padding="5dp"
android:paddingBottom="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_horizontal_margin"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label"
android:textSize="22sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
/>
<RadioGroup
android:id="@+id/priorityChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<RadioButton
android:id="@+id/lowPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Low"/>
<RadioButton
android:id="@+id/medPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium" />
<RadioButton
android:id="@+id/highPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="High" />
</RadioGroup>
</LinearLayout>
Or As You want
android:id="@+id/relativeLayout2"
android:gravity="center_vertical"
android:padding="5dp"
android:paddingBottom="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_horizontal_margin"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label"
android:textSize="22sp"
android:id="@+id/text"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<RadioGroup
android:id="@+id/priorityChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/text"
>
<RadioButton
android:id="@+id/lowPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Low"/>
<RadioButton
android:id="@+id/medPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium" />
<RadioButton
android:id="@+id/highPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="High" />
</RadioGroup>
</RelativeLayout>
**if You want to radio Group center than take in radio group
android:layout_centerHorizontal="true"
Upvotes: 1
Reputation: 1712
You need to align your RadioGroup under your TextView. You should add the id attribute to the TextView and then set the RadioGroup to be below it:
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tvPriorityLabel"
android:textSize="22sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_alignTop="@id/priorityChoice"/>
<RadioGroup
android:id="@+id/priorityChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/text_view">
Also note that you do not need the android:gravity attribute for positioning individual views.
Make sure to checkout the docs on RelativeLayouts and LinearLayouts.
Upvotes: 2
Reputation: 45052
Try this
You need to use property to put view below one another in relative layouts
android:layout_below="@+id/text"
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/dueDateSection"
android:gravity="center_vertical">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="PriorityLabel"
android:textSize="22sp" />
<RadioGroup
android:id="@+id/priorityChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:gravity="center_horizontal"
android:orientation="horizontal">
<RadioButton
android:id="@+id/lowPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Low" />
<RadioButton
android:id="@+id/medPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium" />
<RadioButton
android:id="@+id/highPriority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yHigh" />
</RadioGroup>
</RelativeLayout>
</LinearLayout>
Result
Upvotes: 3