How do you properly align radio buttons in android studio? - android

I have three radio groups each with two button inside of them. As you can see from this picture: http://imgur.com/JQJ0a7A [1] ,the buttons are all lined up nicely in android studio. However, when I run the app in the VM I end up with this: http://imgur.com/nKdth41 [2].
Any ideas why this is occurring? Thanks in advance for any help.
xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="onerepmax.reversepyramid.RPworkout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/workoutButton"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:width="175dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/warmupButton"
android:id="#+id/button3"
android:width="175dp"
android:layout_alignBottom="#+id/button"
android:layout_toRightOf="#+id/button"
android:layout_toEndOf="#+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/liftText"
android:layout_marginTop="50dp"
android:layout_below="#+id/button"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="#+id/weightText1"
android:layout_marginRight="36dp"
android:layout_marginEnd="36dp"
android:layout_alignTop="#+id/repText1"
android:layout_toLeftOf="#+id/repText1"
android:layout_toStartOf="#+id/repText1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="#+id/repText1"
android:layout_marginTop="66dp"
android:layout_below="#+id/liftText"
android:layout_alignLeft="#+id/liftText"
android:layout_alignStart="#+id/liftText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="#+id/weightText2"
android:layout_alignTop="#+id/weightText1"
android:layout_marginTop="70dp"
android:layout_alignLeft="#+id/weightText3"
android:layout_alignStart="#+id/weightText3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="#+id/repText2"
android:layout_alignTop="#+id/repText1"
android:layout_alignLeft="#+id/repText1"
android:layout_alignStart="#+id/repText1"
android:layout_marginTop="70dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="#+id/weightText3"
android:layout_alignTop="#+id/weightText2"
android:layout_marginTop="70dp"
android:layout_alignLeft="#+id/weightText1"
android:layout_alignStart="#+id/weightText1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="#+id/repText3"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/repText1"
android:layout_alignStart="#+id/repText1"
android:layout_alignTop="#+id/repText2"
android:layout_marginTop="70dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/nextButton"
android:id="#+id/nextButton"
android:layout_marginBottom="39dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="#+id/button3"
android:layout_alignEnd="#+id/button3"
android:layout_above="#+id/weightText3"
android:orientation="horizontal"
android:layout_toRightOf="#+id/nextButton"
android:layout_toEndOf="#+id/nextButton"
android:layout_below="#+id/liftText"
android:id="#+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton2"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="59dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton"
android:checked="false"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="59dp"
android:buttonTint="#d32323"/>
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="#+id/radioGroup"
android:layout_alignEnd="#+id/radioGroup"
android:layout_below="#+id/weightText1"
android:layout_alignBottom="#+id/weightText3"
android:orientation="horizontal"
android:layout_toEndOf="#+id/button"
android:layout_toRightOf="#+id/button">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton3"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="45dp"
android:layout_marginLeft="45dp"
android:layout_marginStart="45dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton4"
android:checked="false"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="45dp"
android:buttonTint="#d32323"/>
</RadioGroup>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignRight="#+id/radioGroup"
android:layout_alignEnd="#+id/radioGroup"
android:layout_below="#+id/repText2"
android:layout_above="#+id/nextButton">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton5"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="45dp"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton6"
android:checked="false"
android:layout_marginRight="37dp"
android:layout_marginEnd="37dp"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="45dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>

This should solve your alignment issue, also there is no need to have to label text views, instead do:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="onerepmax.reversepyramid.RPworkout">
<!-- Even spaced buttons above -->
<LinearLayout
android:id="#+id/btn_wrapper"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Workout"
android:id="#+id/button"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Warmup"
android:id="#+id/button3"
android:layout_weight="1"/>
</LinearLayout>
<!-- Centered Text -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/liftText"
android:layout_marginTop="50dp"
android:layout_below="#+id/btn_wrapper"
android:layout_centerHorizontal="true" />
<!-- Centered Radio Group with Label 1 -->
<RelativeLayout
android:id="#+id/set_1"
android:layout_below="#+id/liftText"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="#+id/txt_lbs_1"
android:text="xxx lbs xx reps"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_toRightOf="#+id/txt_lbs_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerVertical="true"
android:id="#+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton2"
android:layout_marginLeft="16dp"
android:checked="false"
android:buttonTint="#2ebb39"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton"
android:checked="false"
android:layout_marginLeft="16dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
<!-- Centered Radio Group with Label 2 -->
<RelativeLayout
android:id="#+id/set_2"
android:layout_below="#+id/set_1"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="#+id/txt_lbs_2"
android:text="xxx lbs xx reps"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_toRightOf="#+id/txt_lbs_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:id="#+id/radioGroup2">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonPassTwo"
android:layout_marginLeft="16dp"
android:checked="false"
android:buttonTint="#2ebb39"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonFailTwo"
android:checked="false"
android:layout_marginLeft="16dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
<!-- Centered Radio Group with Label 3 -->
<RelativeLayout
android:id="#+id/set_3"
android:layout_below="#+id/set_2"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="#+id/txt_lbs_3"
android:text="xxx lbs xx reps"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_toRightOf="#+id/txt_lbs_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:id="#+id/radioGroup3">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonPassThree"
android:layout_marginLeft="16dp"
android:checked="false"
android:buttonTint="#2ebb39"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonFailThree"
android:checked="false"
android:layout_marginLeft="16dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Workout"
android:id="#+id/nextButton"
android:layout_marginBottom="39dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
And when you want to set something like "200 lbs 10 reps" for the TextView with txt_lbs_1
do:
TextView mTextViewLbs1 = (TextView) findViewById(R.id.txt_lbs_1);
mTextViewLbs1.setText(String.format("%1$d lbs %2$d reps", 200, 3));
This yields:
Good luck and hope this points you in a better direction.
Happy Coding!

Related

Buttons in layout are crammed to left side of screen

I have two buttons (Next and Cancel) in my layout that are crammed to the left side of the screen and it won't allow me to adjust them past the centre. I tried playing around with the attributes of the buttons to fix it, I even considered placing these buttons in a linear layout in order to organize them with no luck.
I've attached my .xml file, I would really appreciate it if someone can point out where I'm going wrong.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<EditText
android:id="#+id/emailAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:text="Email"
android:layout_marginTop="79dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/mobileNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:text="Mobile"
android:layout_alignParentStart="true"
android:layout_below="#+id/emailAddress"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="Password"
android:layout_alignParentStart="true"
android:layout_below="#+id/mobileNum"
android:layout_centerHorizontal="true" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="23dp"
android:layout_below="#+id/password"
android:layout_above="#+id/loginButton"
android:layout_alignEnd="#+id/password">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rider"
android:id="#+id/riderRadioButton"
android:layout_alignTop="#+id/driverRadioButton"
android:layout_toEndOf="#+id/driverRadioButton"
android:layout_alignBottom="#+id/driverRadioButton"
android:checked="false"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver"
android:id="#+id/driverRadioButton"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:checked="false"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Your email and number are used to send you ride confirmations"
android:id="#+id/messageTextView"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="79dp"
android:textAlignment="center"
android:textSize="13dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/messageTextView">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/nextButton"
android:layout_marginTop="35dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="#+id/cancelButton"
android:layout_marginEnd="85dp"/>
</LinearLayout>
At the time, I didn't have experience with xml files. However, I have been able to fix it now. I removed the LinearLayout which contained the buttons, and played around with some attributes to get it to work.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="daniaghazal.com.hitchhikr.SignUpPage">
<EditText
android:id="#+id/emailAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email"
android:layout_marginTop="79dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/mobileNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="Mobile"
android:layout_alignParentStart="true"
android:layout_below="#+id/emailAddress"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"
android:layout_alignParentStart="true"
android:layout_below="#+id/mobileNum"
android:layout_centerHorizontal="true" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="23dp"
android:layout_below="#+id/password"
android:checkedButton="#+id/riderRadioButton"
android:layout_alignBottom="#+id/messageTextView"
android:layout_alignParentEnd="true">
<RadioButton
android:id="#+id/riderRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rider"
android:layout_alignTop="#+id/driverRadioButton"
android:layout_toEndOf="#+id/driverRadioButton"
android:layout_alignBottom="#+id/driverRadioButton"
android:checked="false"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="#+id/driverRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:checked="false"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
<TextView
android:id="#+id/messageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Your email and number are used to send you ride confirmations"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="79dp"
android:textAlignment="center"
android:textSize="13dp"/>
<Button
android:id="#+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_marginLeft="75dp"
android:layout_marginTop="20dp"
android:layout_below="#+id/messageTextView"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginTop="20dp"
android:layout_below="#+id/radioGroup"
android:layout_toEndOf="#+id/nextButton" />
</RelativeLayout>
Try to set android:gravity attribute of parent layout to center it's content. Something like:
EDIT
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<EditText
android:id="#+id/emailAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:text="Email"
android:layout_marginTop="79dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/mobileNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:text="Mobile"
android:layout_alignParentStart="true"
android:layout_below="#+id/emailAddress"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="Password"
android:layout_alignParentStart="true"
android:layout_below="#+id/mobileNum"
android:layout_centerHorizontal="true"/>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="23dp"
android:layout_below="#+id/password"
android:checkedButton="#+id/riderRadioButton"
android:layout_alignBottom="#+id/messageTextView"
android:layout_alignParentEnd="true">
<RadioButton
android:id="#+id/riderRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rider"
android:layout_alignTop="#+id/driverRadioButton"
android:layout_toEndOf="#+id/driverRadioButton"
android:layout_alignBottom="#+id/driverRadioButton"
android:checked="false"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:id="#+id/driverRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:checked="false"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Your email and number are used to send you ride confirmations"
android:id="#+id/messageTextView"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="79dp"
android:textAlignment="center"
android:textSize="13dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/messageTextView"
android:layout_marginTop="20dp"
android:gravity="center_horizontal">
<Button
android:id="#+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"/>
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>

Aligning buttons at the button of the screen - Android

I am trying to align my buttons at the bottom of the screen using layouts but I cannot figure what's wrong with my code. I have tried several options by nesting different layouts but with no good outcome. it looks like this right now
And my code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/relLayout"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:clickable="true"
android:focusableInTouchMode="true"
tools:context="com.example.aurora.personalinformation.MainActivity">
<!-- Make the parent view clickable and focusable -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/title"
android:layout_centerHorizontal="true"
android:id="#+id/title"
android:textColor="#FF0000"
android:textSize="25dp"
android:textAlignment="center" />
<TextView
android:id="#+id/nameLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp"
android:layout_marginTop="40dp"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText android:id="#+id/edit_name"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter name"
android:layout_alignBottom="#id/nameLable"
android:layout_toRightOf="#+id/phoneLable"
android:layout_toEndOf="#+id/phoneLable"
/>
<TextView
android:id="#+id/addressLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_alignBottom="#+id/addressField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:id="#+id/addressField"
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your address"
android:layout_below="#id/edit_name"
android:layout_alignLeft="#id/edit_name"
android:layout_alignStart="#id/edit_name" />
<TextView
android:id="#+id/phoneLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/phone"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp"
android:layout_below="#id/addressField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"/>
<EditText
android:id="#+id/phoneField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your phone number"
android:layout_below="#id/addressField"
android:layout_toRightOf="#id/phoneLable"
android:layout_toEndOf="#id/phoneLable" />
<TextView
android:id="#+id/emailLable"
android:layout_below="#id/phoneLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="#+id/emailField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:layout_below="#id/phoneField"
android:layout_alignLeft="#id/phoneField"
android:layout_alignStart="#id/phoneField" />
<TextView
android:id="#+id/genderLable"
android:layout_below="#id/emailLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gender"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp" />
<Spinner
android:id="#+id/gender"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="#array/gender"
android:layout_alignTop="#+id/genderLable"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/emailField"
android:layout_alignStart="#+id/emailField" />
<TextView
android:id="#+id/country"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Country"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_below="#id/gender"
android:layout_marginTop="15dp"/>
<AutoCompleteTextView
android:id="#+id/countryField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:layout_below="#id/gender"
android:layout_toRightOf="#id/phoneLable"
android:layout_toEndOf="#id/phoneLable" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
just give your last RelativeLayout like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_below="#+id/countryField"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
One more thing there is no meaning to give an orientation to RelativeLayout.

how to align text and button in RowTable in Android

I am trying to design my fragment and i would like to create that the text will be exactly above the button and in the center.
for now i just created a 2 RowTables. but i still not succeed to align it as i want.
this is the XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainSearchRelativeLayout"
tools:context="com.example.matant.gpsportclient.Controllers.SearchEventFragmentController"
android:background="#ffffff">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/secondSearchLayout"
android:layout_height="wrap_content">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/radioGroupSearchFragment">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search by current location"
android:id="#+id/radioButtonSearchCurrentLocation"
android:checked="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search by specific address"
android:id="#+id/radioButtonSearchSpecificAdd"
android:checked="false" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="#+id/editText"
android:hint="Please insert real Street address" />
</RadioGroup>
<View
android:id="#+id/divider1"
android:layout_width="fill_parent"
android:layout_height="6dp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/radioGroupSearchFragment"
/>
<ScrollView
android:layout_width="match_parent"
android:id="#+id/searchScrollView"
android:layout_below="#id/divider1"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/mandatorySearchLayout"
android:layout_below="#+id/divider1"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Date Ranges"
android:id="#+id/textViewEventDateRange"
android:textColor="#000000"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textViewSearchMandatory1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From"
android:id="#+id/buttonSearchEventFrom"
android:layout_below="#+id/textViewEventDateRange"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To"
android:id="#+id/buttonSearchEventTo"
android:layout_below="#+id/buttonSearchEventFrom"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*All the fields are mandatory"
android:id="#+id/textViewSearchMandatory1"
android:textColor="#FF0000"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TableRow
android:layout_width="match_parent"
android:id="#+id/row1"
android:layout_below="#+id/buttonSearchEventTo"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start in"
android:layout_marginLeft="50dp"
android:id="#+id/textView6" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End in"
android:layout_marginLeft="150dp"
android:id="#+id/textView7" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/row2"
android:layout_below="#id/row1"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:layout_marginLeft="20dp"
android:id="#+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:layout_marginLeft="70dp"
android:id="#+id/button" />
</TableRow>
</RelativeLayout>
</ScrollView>
<View
android:id="#+id/divider2"
android:layout_width="fill_parent"
android:layout_height="6dp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/searchScrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="70dp" />
</RelativeLayout>
and this is what i got:
As you haven't underline, which buttons and textViews you want to align, I suggested, that you want to get something like this:
To do this, I'd advocate to get rid of TableRows and replace them with, for example, LinearLayouts:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainSearchRelativeLayout"
tools:context="com.example.matant.gpsportclient.Controllers.SearchEventFragmentController"
android:background="#ffffff">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/secondSearchLayout"
android:layout_height="wrap_content">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/radioGroupSearchFragment">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search by current location"
android:id="#+id/radioButtonSearchCurrentLocation"
android:checked="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search by specific address"
android:id="#+id/radioButtonSearchSpecificAdd"
android:checked="false" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPostalAddress"
android:ems="10"
android:id="#+id/editText"
android:hint="Please insert real Street address" />
</RadioGroup>
<View
android:id="#+id/divider1"
android:layout_width="fill_parent"
android:layout_height="6dp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/radioGroupSearchFragment"
/>
<ScrollView
android:layout_width="match_parent"
android:id="#+id/searchScrollView"
android:layout_below="#id/divider1"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/mandatorySearchLayout"
android:layout_below="#+id/divider1"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Date Ranges"
android:id="#+id/textViewEventDateRange"
android:textColor="#000000"
android:textStyle="bold"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textViewSearchMandatory1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From"
android:id="#+id/buttonSearchEventFrom"
android:layout_below="#+id/textViewEventDateRange"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To"
android:id="#+id/buttonSearchEventTo"
android:layout_below="#+id/buttonSearchEventFrom"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*All the fields are mandatory"
android:id="#+id/textViewSearchMandatory1"
android:textColor="#FF0000"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<LinearLayout
android:layout_below="#+id/buttonSearchEventTo"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start in"
android:id="#+id/textView6" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End in"
android:id="#+id/textView7" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
<View
android:id="#+id/divider2"
android:layout_width="fill_parent"
android:layout_height="6dp"
android:background="#android:color/darker_gray"
android:layout_below="#+id/searchScrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="70dp" />
</RelativeLayout>
The last thing then to think of - to remove the default button's shadow around, to make them fully align - this question is covered here - How to remove padding around buttons in android?
I hope, it helps

Android radio button text truncated

I have an app that shows a Radio Group with four Radio Buttons whose test is set dynamically. I am no able to get the whole text on a single line.
It gets wrapped on two lines, or truncated at the end. It seems like there is a vertical edge, and text cannot go over it.
My layout is
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="vds.quizmanager.QuizManagerActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="Domanda:" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginTop="24dp"
android:layout_toLeftOf="#+id/button2" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minWidth="#dimen/activity_vertical_margin" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RadioGroup>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:text="Domanda" />
</RelativeLayout>
OK then you can try this code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="Domanda:" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="sdfsgdshfdgsasRFAGRESTDGHFSAFAWhtjygukjtyhergwrqTQETWRYJETRHEWRQEJTUKRYJTRHEAWRWetjyurrutjretwrtjyeukyriu" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="24dp"
android:layout_toLeftOf="#+id/button2" >
<RadioButton
android:id="#+id/radio0"
android:text="Domandaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minWidth="#dimen/activity_vertical_margin" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RadioGroup>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:text="Domanda" />
</RelativeLayout>
This is result:

ViewFliper in layout

i am doing one application in android but i have one problem in layout file
i am doing by viewFliper
here is code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/Quesiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="#string/Question"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroupOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Quesiontext"
android:layout_marginTop="30dp" >
<RadioButton
android:id="#+id/optionOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/option1" />
<RadioButton
android:id="#+id/optionTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option2" />
<RadioButton
android:id="#+id/optionthree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option3" />
<RadioButton
android:id="#+id/optionFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option4" />
</RadioGroup>
<TextView
android:id="#+id/corrertView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroupOptions"
android:layout_marginRight="48dp"
android:text="#string/correct" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/corrertView"
android:layout_below="#+id/corrertView"
android:layout_marginTop="42dp"
android:text="#string/Next"
android:textSize="16sp" />
<Button
android:id="#+id/Btnpervious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btnNext"
android:layout_alignBottom="#+id/btnNext"
android:layout_alignParentLeft="true"
android:text="#string/Pervious"
android:textSize="16sp" />
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewFlipper
android:id="#+id/ViewFlipper01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Quesiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="#string/Question"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroupOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Quesiontext"
android:layout_marginTop="30dp" >
<RadioButton
android:id="#+id/optionOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/option1" />
<RadioButton
android:id="#+id/optionTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option2" />
<RadioButton
android:id="#+id/optionthree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option3" />
<RadioButton
android:id="#+id/optionFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option4" />
</RadioGroup>
<TextView
android:id="#+id/corrertView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroupOptions"
android:layout_marginRight="48dp"
android:text="#string/correct" />
</ViewFlipper>
</RelativeLayout>
</RelativeLayout>
i didnt get it that how i put another button into ViewFliper ..its confusion and generating error...
You haven't closed your ViewFlipper with </ViewFlipper>
Could this be what you are looking for,
android:id="#+id/layout"
You missed a "+" symbol while creating a id.

Categories

Resources