Buttons in layout are crammed to left side of screen - android

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>

Related

Progress bar is not center when under relative layout

I am using relative layout in my android app.
Following is my main.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:gravity="fill"
tools:context="com.example.asdf.MainActivity" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="#drawable/bgg" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginTop="22dp"
android:gravity="center"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:text=" Factualnote is an web annotation application, which helps the users to mark the specific text, element, page, video, etc in a web page and share it to like-minded people.\r\n \r\nAs we know the relevant data has been wide-spreaded across various sites under many intentions, factualnote is a type of social software tool in which factual data are brought forward or narrow down to the web users."
android:textColor="#ffffff"
android:textSize="25sp"
android:textStyle="normal|italic" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<EditText
android:id="#+id/url"
android:layout_width="290dp"
android:layout_height="33dip"
android:layout_above="#+id/button_show"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:background="#ffffff"
android:ems="17"
android:hint="#string/edit_hint"
android:radius="10dp"
android:singleLine="true"
android:text="http://www.zeptoh.com/lynked/sel.html"
android:textColor="#000000"
android:textSize="16sp" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/blue_button"
android:text="#string/button_title"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="#string/undo"
android:textColor="#ffffff" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="Mark"
android:textColor="#ffffff" />
<Button
android:id="#+id/done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="10"
android:background="#drawable/blue_button2"
android:text="Generate"
android:textColor="#ffffff" />
<Button
android:id="#+id/redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="#string/redo"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:id="#+id/rl2"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<EditText
android:id="#+id/name"
android:layout_width="250dp"
android:layout_height="33dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#ffffff"
android:ems="17"
android:layout_gravity="center_horizontal"
android:hint="Enter Title"
android:singleLine="true"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="#+id/desc"
android:layout_width="250dp"
android:layout_height="33dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:background="#ffffff"
android:ems="17"
android:layout_gravity="center_horizontal"
android:hint="Description about your note"
android:singleLine="true"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:id="#+id/privateText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/desc"
android:layout_below="#+id/desc"
android:layout_marginTop="10dp"
android:text="Private Note:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:textSize="20sp"
android:checked="true"
android:buttonTint="#color/desing_color"
android:textStyle="bold" />
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/privateText"
android:layout_toRightOf="#+id/privateText"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:text="Yes"
android:buttonTint="#color/desing_color"
android:textColor="#ffffff"
android:textSize="15sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/privateText"
android:layout_marginLeft="14dp"
android:layout_toRightOf="#+id/yes"
android:text="No"
android:textColor="#ffffff"
android:textSize="15sp"
android:checked="true"
android:buttonTint="#color/desing_color"
android:textStyle="bold" />
</RadioGroup>
<Button
android:id="#+id/generate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#drawable/blue_button"
android:layout_below="#+id/radioSex"
android:layout_marginTop="10dp"
android:layout_marginLeft="70dp"
android:textColor="#ffffff"
android:text="Generate Note" />
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_below="#+id/radioSex"
android:background="#drawable/blue_button"
android:layout_marginTop="10dp"
android:layout_marginLeft="200dp"
android:textColor="#ffffff"
android:text="Back" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
I put progress bar to center in horizontal and vertical. But that is placed on top of the screen only.
When I remove Linear layout rl2, progress bar appears center.
What I need to do to get progress bar in center even I have rl2.
Try adding
android:layout_centerInParenta="true"
to the progressbar and tell me if it works.
Did you try to remove android:gravity="fill" from the main container? (the first relative layout, the one that contains all the layout)
add the following line in your xml file,
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
if its not work, then first add progressbar and then add your views. Maybe it will work.

How to align textview in wrap content right for bigger screen in android studio?

[My Layout]
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Login"
android:background="#drawable/background">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/efield"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/textView_username" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Username :"
android:id="#+id/textView_username"
android:textColor="#FFFFFF"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:layout_above="#+id/textView_attempt"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Password :"
android:id="#+id/textView_password"
android:textColor="#FFFFFF"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_above="#+id/textView_attempt_count"
android:layout_alignRight="#id/editText_pass"
android:layout_alignEnd="#id/editText_pass"
android:gravity="right" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText_user"
android:text="Name"
android:textColor="#FFFFFF"
android:layout_alignTop="#+id/textView_username"
android:layout_alignRight="#+id/imageView"
android:layout_alignEnd="#+id/imageView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText_password"
android:text="Password"
android:textColor="#FFFFFF"
android:layout_alignTop="#+id/textView_password"
android:layout_alignLeft="#id/textView_password"
android:layout_alignStart="#+id/editText_user" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Attempts :"
android:id="#+id/textView_attempt"
android:textColor="#FFFFFF"
android:paddingTop="40dp"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/textView_username"
android:layout_alignEnd="#+id/textView_username" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textView_attempt_count"
android:layout_alignBottom="#+id/textView_attempt"
android:layout_alignLeft="#+id/editText_password"
android:layout_alignStart="#+id/editText_password"
android:textColor="#FFFFFF"/>
<Button
android:layout_width="160dp"
android:layout_height="40dp"
android:text="Login"
android:id="#+id/button_login"
android:background="#drawable/statelistdrawable"
android:textColor="#drawable/txco"
android:layout_above="#+id/textView_time"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView_time"
android:gravity="center"
android:textColor="#FFFFFF"
android:layout_above="#+id/button_FP"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Forgot Password"
android:id="#+id/button_FP"
android:background="#android:color/transparent"
android:textColor="#drawable/tbutton"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
My Layout 1
Want to remove space between "Username" textview and "Name" edittext in Landscape. My layout is looking proper in portrait but gives space in between textview and edittext in landscape.

Android Scroll View not filling Device Screen

Hello I have a fragment that loads an Xml file. The xml file code is given below.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:orientation="vertical"
android:scrollbars="vertical"
android:background="#2f3799"
android:fillViewport="true"
tools:context=".NewItem"
android:paddingEnd="0dp"
android:paddingStart="0dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#111a42"
android:weightSum="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="SUBMIT YOUR POST"
android:id="#+id/textHeading"
android:textSize="15pt"
android:textColor="#ffffff"
android:textAlignment="center"
android:layout_weight="20" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Category"
android:textColor="#ffffff"
android:id="#+id/textCategory"
android:layout_alignParentStart="true"
android:layout_marginTop="36dp" />
<GridLayout
android:id="#+id/gridLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioGroup
android:id="#+id/categoryRadio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/motoRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#ffffff"
android:text="Motorbike" />
<RadioButton
android:id="#+id/carRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#ffffff"
android:text="Car" />
<RadioButton
android:id="#+id/otherRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Others"
android:textColor="#ffffff"/>
</RadioGroup>
</GridLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#ffffff"
android:id="#+id/textTitle" />
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/edittext_bg"
android:id="#+id/titleText"
android:inputType="text"
android:hint="Item Title"
android:singleLine="true"
android:visibility="visible"
android:typeface="sans"
android:layout_weight="0.65"
android:layout_marginLeft="10dp"
android:layout_gravity="left"
android:layout_below="#id/textTitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subject"
android:textColor="#ffffff"
android:id="#+id/textSubject" />
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:inputType="text"
android:background="#drawable/edittext_bg"
android:id="#+id/subjectText"
android:singleLine="true"
android:visibility="visible"
android:layout_marginLeft="10dp"
android:typeface="sans"
android:hint="Item Subject"
android:layout_weight="0.65"
android:layout_gravity="left" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Content"
android:textColor="#ffffff"
android:id="#+id/textContent"
android:layout_below="#+id/subjectText"/>
<EditText
android:layout_width="300dp"
android:layout_height="100dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/contentText"
android:background="#drawable/edittext_bg"
android:layout_marginLeft="10dp"
android:textAlignment="textStart"
android:textColor="#232121"
android:layout_below="#id/textContent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Source"
android:textColor="#ffffff"
android:id="#+id/textSource"
android:layout_below="#+id/contentText"/>
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:inputType="text"
android:background="#drawable/edittext_bg"
android:id="#+id/sourceText"
android:layout_marginLeft="10dp"
android:layout_above="#+id/button"
android:layout_below="#+id/textSource"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:textColor="#ffffff"
android:id="#+id/button"
android:onClick="submitItem"
android:layout_gravity="center" />
</LinearLayout>
</ScrollView>
Even after setting the android:fillViewport="true", the view does not fill the entire device screen. See the picture below for clarity. Awaiting your response. Thanks
It seems you've the default paddings, check your activity layout and delete these lines:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
change your dimens file
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
then in the layout
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
Delete all padding lines from your xml
Your activity file contains Padding in main layout tag.

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 do you properly align radio buttons in android studio?

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!

Categories

Resources