This is my *activity_login.xml*
<?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:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
tools:ignore="ExtraText" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/userid"
android:layout_centerHorizontal="true"
android:text="#string/userid"
android:textSize="20sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/password"
android:layout_centerHorizontal="true"
android:text="#string/password"
android:textSize="20sp" />
<EditText
android:id="#+id/userid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView3"
android:layout_alignRight="#+id/password"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/login"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_above="#+id/newuser"
android:layout_alignRight="#+id/textView3"
android:layout_marginBottom="27dp"
android:gravity="center"
android:text="#string/button_login" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/login"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="#+id/register"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="42dp"
android:gravity="center"
android:text="#string/button_register" />
<TextView
android:id="#+id/newuser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/register"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"
android:text="#string/newuser" />
</RelativeLayout>
I want pos_malaysia.png to be set as my login page background on the top center on the screen.. I saw some of them say use <bitmap> .
The thing is when I replace RelativeLayout with bitmap all the android:layout_above="#+id/userid" and android:layout_centerHorizontal="true" cannot be used since its only applies for RelativeLayout. what should I do to maintain the layout with added background?
There are 2 possible solutions for it.
1st add android:background="#drawable/[PIC]" to your Relative Layout.
2nd add ImageView as 1st layer (on bottom) of Relative Layout.
Depends on what kind of background (logo, image) you should consider using 9patch, so it will nicely scale.
Try
<RelativeLayout>
<ImageView
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true">
</ImageView>
</RelativeLayout>
Try this. You can same in linear layout as well
<?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:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
tools:ignore="ExtraText"
android:background="#drwable/your_bg_image"
>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/userid"
android:layout_centerHorizontal="true"
android:text="#string/userid"
android:textSize="20sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/password"
android:layout_centerHorizontal="true"
android:text="#string/password"
android:textSize="20sp" />
<EditText
android:id="#+id/userid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView3"
android:layout_alignRight="#+id/password"
android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="#+id/login"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_above="#+id/newuser"
android:layout_alignRight="#+id/textView3"
android:layout_marginBottom="27dp"
android:gravity="center"
android:text="#string/button_login" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/login"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="#+id/register"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="42dp"
android:gravity="center"
android:text="#string/button_register" />
<TextView
android:id="#+id/newuser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/register"
android:layout_centerHorizontal="true"
android:layout_marginBottom="14dp"
android:text="#string/newuser" />
</RelativeLayout>
try this:
<?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:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
tools:ignore="ExtraText" >
<ImageView
android:id="#+id/imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/*****YOUR IMAGE NAME****"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
if you would like to add background use
android:background="#drawable/image_name"
(provided that the image you are planning to load is in the Project resources.)
in widget or RelativeLayout
if you would like to maintain its size create syle or just create imageView
Related
I am trying to develop a simple app for project management. The problem is with the xml layout of the app screens. The app screens are proportionally not very well put in different devices. Some elements are even hidden in some devices due to lack of space.
I already tried using both linear layout and relative layout. I've always used the "Match_parent" attribute to both the width and height of the relative layout and linear layout parent block. But still in some screen sizes, some elements are not showing, they are below the display area.
<RelativeLayout
android:id="#+id/layout1"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context=".login"
android:paddingTop="20dp"
>
<ImageView
android:id="#+id/loginImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/login_logo"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="LOGIN"
android:textColor="#color/orange"
android:textSize="50sp"
android:layout_below="#id/loginImage"
/>
<EditText
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logintextbackground"
android:layout_centerHorizontal="true"
android:layout_below="#id/loginText"
android:hint="Username"
android:textColorHint="#color/lightOrange"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:maxLength="15"
/>
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logintextbackground"
android:layout_centerHorizontal="true"
android:layout_below="#id/username"
android:hint="Password"
android:textColorHint="#color/lightOrange"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:inputType="textPassword"
android:maxLength="16"
/>
<Button
android:id="#+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/login_button"
android:layout_below="#id/password"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/orText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="or"
android:textSize="20dp"
android:textColor="#color/orange"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
/>
<Button
android:id="#+id/signUpButtonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/signup"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
/>
Put a ScrollView as parent of your RelativeLayout and you should be fine. Refer code below :
<ScrollView 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:background="#color/white">
<RelativeLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:paddingTop="20dp"
tools:context=".login">
<ImageView
android:id="#+id/loginImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/login_logo" />
<TextView
android:id="#+id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginImage"
android:layout_centerHorizontal="true"
android:text="LOGIN"
android:textColor="#color/orange"
android:textSize="50sp" />
<EditText
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginText"
android:layout_centerHorizontal="true"
android:background="#drawable/logintextbackground"
android:hint="Username"
android:maxLength="15"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:textColorHint="#color/lightOrange" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/username"
android:layout_centerHorizontal="true"
android:background="#drawable/logintextbackground"
android:hint="Password"
android:inputType="textPassword"
android:maxLength="16"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:textColorHint="#color/lightOrange" />
<Button
android:id="#+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/password"
android:layout_centerHorizontal="true"
android:background="#drawable/login_button" />
<TextView
android:id="#+id/orText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
android:text="or"
android:textColor="#color/orange"
android:textSize="20dp" />
<Button
android:id="#+id/signUpButtonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="#drawable/signup" />
</RelativeLayout>
</ScrollView>
For future development, I would suggest you to use ConstraintLayout instead of LinearLayout or RelativeLayout as it provides less nesting of the views.
I have an XML script and in the android studio editor, the preview window shows the screen as it is supposed to look (see picture below). When running on the emulator it looks like all components shift position.
Here is the code for the 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:background="#color/colorWhite"
tools:context="com.example.ansel.companionapp.Main_menu">
<ImageView
android:id="#+id/logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="40dp"
android:layout_marginEnd="113dp"
android:src="#drawable/companionapp" />
<TextView
android:id="#+id/infoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:paddingTop="20dp"
android:text="Large Text"
android:textColor="#color/colorPrimary"
android:textSize="18dp" />
<Button
android:id="#+id/TPS_button"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:layout_below="#+id/infoText"
android:layout_alignStart="#+id/infoText"
android:layout_marginStart="-25dp"
android:layout_marginTop="53dp"
android:background="#drawable/button_shape"
android:onClick="TPS"
android:text="#string/ThirdPersonShooter"
android:textColor="#color/colorWhite" />
<Button
android:id="#+id/TDS_Button"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:layout_below="#+id/TPS_button"
android:layout_alignStart="#+id/infoText"
android:layout_marginStart="-23dp"
android:layout_marginTop="38dp"
android:background="#drawable/button_shape"
android:onClick="TwoDS"
android:text="#string/TwoDimensionalShooter"
android:textColor="#color/colorWhite" />
</RelativeLayout>
Here is my desired versus actual layout.
I removed all the negative margins and alignings and added for all the views:
android:layout_centerHorizontal="true"
So check this:
<?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:background="#color/colorWhite"
tools:context="com.example.ansel.companionapp.Main_menu">
<ImageView
android:id="#+id/logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:src="#drawable/companionapp" />
<TextView
android:id="#+id/infoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:paddingTop="20dp"
android:text="Large Text"
android:textColor="#color/colorPrimary"
android:textSize="18dp" />
<Button
android:id="#+id/TPS_button"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:layout_below="#+id/infoText"
android:layout_centerHorizontal="true"
android:layout_marginTop="53dp"
android:background="#drawable/button_shape"
android:onClick="TPS"
android:text="#string/ThirdPersonShooter"
android:textColor="#color/colorWhite" />
<Button
android:id="#+id/TDS_Button"
android:layout_width="146dp"
android:layout_height="wrap_content"
android:layout_below="#+id/TPS_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:background="#drawable/button_shape"
android:onClick="TwoDS"
android:text="#string/TwoDimensionalShooter"
android:textColor="#color/colorWhite" />
</RelativeLayout>
enter image description here
As you can see there is a shadow around the ticket. I cannot make this because I am using the library (TicketView) and there is a problem with Scallops
HERE IS MY CODE
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#f3f6f9">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="52.5dp"
android:layout_marginEnd="18dp"
android:orientation="vertical"
android:elevation="14dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="37.5dp"
android:background="#drawable/gradient_tickets">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:elevation="2dp"
android:text="Bus 79"
android:textColor="#fefefe"
android:textSize="12sp"
tools:layout_editor_absoluteX="37dp"
tools:layout_editor_absoluteY="69dp" />
<ImageView
android:id="#+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:scaleX="0.6"
android:scaleY="0.6"
android:src="#drawable/arrow_list" />
<TextView
android:id="#id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/text1"
android:layout_marginTop="40dp"
android:layout_marginBottom="10dp"
android:text="11/03/2017"
android:textColor="#a4158a"
android:textSize="12sp" />
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/img1"
android:layout_alignParentRight="false"
android:layout_alignParentBottom="false"
android:layout_marginTop="40dp"
android:text="$0.30"
android:textColor="#a4158a"
android:textSize="12sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.vipulasri.ticketview.TicketView
android:id="#+id/ticketView"
android:layout_width="wrap_content"
android:layout_height="142dp"
app:ticketBackgroundColor="#FFFFFF"
app:ticketDividerColor="#16191c"
app:ticketDividerDashGap="4dp"
app:ticketDividerDashLength="3dp"
app:ticketDividerPadding="1.5dp"
app:ticketDividerType="dash"
app:ticketDividerWidth="0.5dp"
app:ticketOrientation="horizontal"
app:ticketScallopPositionPercent="25.7"
app:ticketScallopRadius="7dp"
app:ticketShowBorder="false"
app:ticketShowDivider="true"
/>
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20.5dp"
android:layout_marginTop="16.5dp"
android:elevation="2dp"
android:text="12/03/2017"
android:textColor="#a4158a"
android:textSize="10sp" />
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/ticketView"
android:layout_alignRight="#+id/ticketView"
android:layout_marginTop="16.5dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
android:elevation="2dp"
android:text="$0.30"
android:textColor="#a4158a"
android:textSize="10sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="31dp"
android:layout_marginTop="47dp"
android:layout_marginRight="31dp"
android:layout_marginBottom="45dp"
android:elevation="3dp"
android:src="#drawable/barcode_img" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
I need to have a shadow there but I cannot manage to do it. Also I used the TicketView which is for making the form of the ticket. Could u please say what I need to add there in order to have such a shadow?
You can use CardView. There is a parameter which app:cardElevation.
But if it's not possible, You can create a drawable and you can create shadow with using gradient.
I'm trying to center the chilldren of my relative layout in the center of my screen but it's acting like it's aligned to the top of the parent and I can't figure out why.
my .XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="#f70909">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
I've tried making the parent a relativelayout without success and it won't align to the bottom either. Initially I thought the layout wasn't filling the whole screen but since its height and width are match_parent I don't think that's the problem. in android studio it is displaying correctly though so I must be missing something small.
I also tried using the gravity and layoutgravity parameters and a combination of the two but without success
Edit: I need the views to stay in the same formation relative to each other but centered in the screen vertically.
Edit 2:I set the background of the RelativeLayout to red and got this: So the relativelayout isn't filling my screen.
Edit 3:
Edit 4:
try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f70909">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:src="#drawable/dice"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage"
android:layout_centerHorizontal="true"
android:layout_below="#+id/imageView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_below="#+id/editUserSplash" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_centerHorizontal="true"
android:layout_below="#+id/editPasswordSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:layout_centerHorizontal="true"
android:indeterminate="true"
android:layout_below="#+id/btnSplash" />
</RelativeLayout>
</RelativeLayout>
Try something like this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:adjustViewBounds="true"
android:layout_centerInParent="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerInParent="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textMessage" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:gravity="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/prgSplash"
style="#android:style/Widget.DeviceDefault.ProgressBar.Large"
android:indeterminate="true" />
</LinearLayout>
</RelativeLayout>
UPDATE:
If setting the xml in an AlertDialog, it's possible that there is a space allotted at the bottom. I google and found this alert_dialog.xml for reference. It seems that there is a buttonPanel at the bottom with a minimum height of 54dip.
<LinearLayout android:id="#+id/buttonPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="54dip"
android:orientation="vertical" >
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="4dip"
android:paddingStart="2dip"
android:paddingEnd="2dip"
android:measureWithLargestChild="true">
<LinearLayout android:id="#+id/leftSpacer"
android:layout_weight="0.25"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
<Button android:id="#+id/button1"
android:layout_width="0dip"
android:layout_gravity="start"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button3"
android:layout_width="0dip"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<Button android:id="#+id/button2"
android:layout_width="0dip"
android:layout_gravity="end"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<LinearLayout android:id="#+id/rightSpacer"
android:layout_width="0dip"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
I think this may help you
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textMessage"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editUserSplash"
android:hint="Username"
android:layout_below="#+id/textMessage"
android:gravity="center" />
<EditText
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editPasswordSplash"
android:hint="Password"
android:layout_below="#+id/editUserSplash"
android:gravity="center" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/btnSplash"
android:layout_below="#+id/editPasswordSplash"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Thanks to ank I was able to figure out that the reason why the RelativeLayout didn't fill my screen is that I used it in an alertDialog. So RelativeLayouts parent isn't the screen but the alertDialog. Since an alertDialog wraps its content it doesn't fill the entire screen.
I am trying to add a background color to the search form area of a RelativeLayout in my Android app in Xamarin. Basically I have an EditText and a button that should be contained within a colored background at the top of the screen. Using the code below, the background color is applied but my EditText and button disappear while the content below them move up and take their place. Here's my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:screenOrientation="portrait"
android:background="#ffffff">
<RelativeLayout
android:id="#+id/TestLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EAF4F9">
<com.neopixl.pixlui.components.textview.TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Heading"
pixlui:typeface="Lato-Bold.ttf"
android:layout_marginBottom="15dp"/>
<EditText
android:inputType="numberDecimal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:id="#+id/SearchField"
android:layout_marginRight="10dp"/>
<Button
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:layout_toRightOf="#id/SearchField"
android:id="#+id/btnSearch"
android:layout_alignParentRight="true" />
<TextView
android:text="Use my current location"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_below="#id/SearchField"
android:id="#+id/txtCurrentLocation"
android:gravity="center"/>
</RelativeLayout>
<View
android:id="#+id/strut"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true" />
<com.neopixl.pixlui.components.button.Button
android:id="#+id/btnOne"
android:text="Button One"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_alignRight="#id/strut"
android:layout_alignParentLeft="true"
android:layout_below="#id/txtCurrentLocation"
pixlui:typeface="Lato-Light.ttf"
android:gravity="center" />
<com.neopixl.pixlui.components.button.Button
android:text="Button Two"
android:id="#+id/btnTwo"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_alignLeft="#id/strut"
android:layout_alignParentRight="true"
android:layout_below="#id/txtCurrentLocation"
android:gravity="center"
pixlui:typeface="Lato-Light.ttf" />
</RelativeLayout>
Should I be utilizing a LinearLayout here instead or is there a better way to construct this?
Try something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<View
android:background="#EAF4F9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/header"
android:layout_alignBottom="#+id/btnOne" />
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="15dp"
android:layout_alignParentTop="true"
android:text="Hello" />
<EditText
android:inputType="numberDecimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
android:layout_alignParentLeft="true"
android:id="#+id/search"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:hint="Search for..." />
<Button
android:text="Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnSearch"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"
android:layout_alignBaseline="#+id/search" />
<TextView
android:text="Use my current location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/search"
android:layout_marginTop="10dp"
android:id="#+id/txtCurrentLocation"
android:gravity="center" />
<Button
android:id="#+id/btnOne"
android:text="Button One"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignRight="#id/strut"
android:layout_alignParentLeft="true"
android:layout_below="#id/txtCurrentLocation"
android:gravity="center" />
</RelativeLayout>
Just replace the buttons and textviews with the pixlui versions where needed.