What is the best place to put a Log In button? - android

I have a log In page with username and password fields. I would like to know the best place to put the log-in button below them. Should it be left-aligned, centered, right-aligned or fill the entire width of the parent?
Is there a industry standard or best practice for Android Log In Buttons?

An idea would be to align them below the edit text views that will be completed. That's the most elegant way to do it.
You can try something like this
Or maybe something like this one

I would say put the login button below the fields. And center it, filling the same amount of space as the fields. This would look the best and would show up great in landscape and portrait.
A lot of companies put a lot of research into the best UI layouts.

The basic layout for login activity that I stumble upon everywhere in a books looks like this:
<TextView android:id="#+id/userNameLbl"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Username: "
android:layout_alignParentTop="true" />
<EditText android:id="#+id/userNameText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/userNameLbl" />
<TextView android:id="#+id/pwdLbl"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/userNameText"
android:text="Password: " />
<EditText android:id="#+id/pwdText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#id/pwdLbl" />
<Button android:id="#+id/btn" android:onClick="doClick"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Login" />
So it's pretty much similar to what #Arkde tried to show you in the second link.
Hope this helps.

Related

UI Layout Issues

First let me attempt to layout what I am trying to accomplish here.
EditText
EditText SearchButton
ListView (search result. there can be only one, ListView with adapter and height of wrap_content seems to work for this, there is a button to add the result to the ListView below. Once the add button is clicked this ListView collapses, which is exactly what I am after)
TextView (label for objects added)
ListView (list of objects added, again I'm using an adapter for the list row layout)
SaveButton
I was going to paste the code that I have but there is just too much to go through. The issues I am having are with the ListViews. Basically, the ListView that contains the objects added will end up pushing the SaveButton off of the screen. I have tried a ton of solutions laid out on this and many other sites but they just don't seem to work right.
Basically, I want the SaveButton to always be at the bottom and I don't want it to get pushed off the screen when the ListView gets too big. The only solution I have found to "work" was to explicitly set the height of the ListViews. However, this causes problems when going from tablet to phone (Nexus7 & Galaxy S3). I thought that using dip for sizes would prevent this from happening but apparently not.
If anyone has a good strategy for creating this type of layout that would be great. Or even a good resource for learning how to use Android's clunky UI system (it really leaves a bit to be desired).
Edit: here is my attempt at using a RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/main_background"
android:orientation="vertical" >
<EditText
android:id="#+id/plan_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:ems="10"
android:hint="#string/plan_name_hint"
android:textColor="#color/text_color" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/object_search_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/plan_name"
android:ems="10"
android:hint="#string/search_objects_text"
android:textColor="#color/text_color" >
</EditText>
<Button
android:id="#+id/objects_search_button"
style="#style/button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/object_search_text"
android:layout_below="#id/plan_name"
android:layout_alignParentRight="true"
android:background="#drawable/black_button"
android:text="#string/search_objects_button_label" />
<ListView
android:id="#+id/search_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/object_search_text"
android:background="#color/main_background"
android:textColor="#color/text_color" >
</ListView>
<TextView
android:id="#+id/objects_list_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/search_result"
android:paddingBottom="8dip"
android:paddingLeft="8dip"
android:text="#string/plan_objects_list_label"
android:textColor="#color/text_color"
android:textSize="22sp"
android:textStyle="bold" />
<ListView
android:id="#+id/plan_objects"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/objects_list_label"
android:background="#color/main_background"
android:textColor="#color/text_color" >
</ListView>
<Button
android:id="#+id/save_plan_button"
style="#style/button_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/black_button"
android:paddingLeft="8dip"
android:text="#string/save_button_label" />
If you think the Android UI system is clunky, you obviously haven't tried to understand it. For most things its extremely well designed.
If you want a certain view (or views) to always be at the bottom, then you want to make your screen a RelativeLayout and put android:layout_alignParentBottom="true" on those element(s). Then add android:layout_above="id" on whatever you want to be above them, where id is the id of the element you want at the bottom.
Make the SaveButton and ListView at the same hierarchy level. e.g if your parent layout is RelativeLayout in your SaveButton add this property android:layout_alignParentBottom="true"
It looks like the only real solution here is to use explicit sizes for the list views and plan accordingly for different screen sizes (i.e. create different layouts for different screens and outlined here.). I was hoping for something a little more generic. Oh well.

Easier way to create and maintain many layouts

I have got an application that is essentially a giant calculator. Within this application it has a total of 75 unique equations and each one has different number of variables and displayed results. I currently have a sliding drawer implemented with the list of the equations of them to choose from and when they click on it, I have a fragment area to put the screen for calculating it. I am currently just implementing a fragment activity for each calculation along with a layout for each one. Does anyone know what best practice is for accomplishing something with this many screens? Do I accomplish them by creating the layout on the fly in the activity? Do I keep it how it is? I am just trying to figure out if the tedious work I am doing with this can be accomplished in an easier manner (I know I have to create the activities to do the work) .
EDIT
The layouts vary in complexity depending on the calcuation. Some of them are to the nth entry from the user and requires a gridview while others will just be simple like example below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=blah blah
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="DCDCDC"
android:orientation="horizontal" >
<EditText
android:id="#+id/etTempInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_below="#+id/tvTempInputLabel"
android:ems="10"
android:inputType="numberSigned" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/tvTempInputLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:text="Medium_Text"
android:textAppearance="?androd:attr/textAppearanceMedium" >
</TextView>
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/etTempInput"
android:layout_toRightOf="#+id/etTempInput" />
<TextView
android:id="#+id/tvTempResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etTempInput"
android:layout_marginTop="22dp"
android:text="Medium_Text"
android:textAppearance="?androd:attr/textAppearanceMedium" >
</TextView>
<Button
android:id="#+id/btnTempCalc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvTempResult"
android:text="Calculate" />
</RelativeLayout>
really hard without seeing the layouts, but it sounds as building up the layouts dynamically ( perhaps from building-blocks in xml ) could tidy things up
The answer I came to with this is to just create each page by itself as there is no consistency between the pages. I looked at several options but none of them met my needs. So look out 75 layouts and code files here I come.

Editbox Hint - Always show hint

I have a textbox with a hint but I want the hint to always be shown, even when there is an input in the TB. Example is the "To" field in the Gmail app.
There are 3 approaches you could use (spoiler - use number 3), since as mentioned in my comment, in the Gmail example , it is not an actual hint:
Using a Linear Layout, getting a cleaner look in my opinion:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="#string/Hint"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:layout_width="fill_parent"
android:inputType="text"
android:layout_height="wrap_content"/>
</LinearLayout>
Using a Relative Layout, getting a result that mimics the Gmail App:
Note: might be problematic since the text will be displayed on top of the hint, see solution 3.
<RelativeLayout android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="#string/Hint"
android:paddingLeft="10dp"
android:layout_marginBottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText android:layout_width="fill_parent"
android:inputType="text"
android:layout_height="wrap_content"/>
Result are as shown in this image:
Edit:
using a Drawable:
This seems a better solution (I personally just created it from snipping the 1:1 display of the TextView, will be in correct measurements this way), this will allow a cleaner layout code, and the text will be aware of the drawable:
<RelativeLayout android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText android:layout_width="fill_parent"
android:inputType="text"
android:gravity="top"
android:drawableLeft="#drawable/Hint"
android:layout_height="wrap_content"/>
The first thing that came to mind is to insert two editText layout relative layout.
First over second.at the top of that - put background as
android.R.color.transparent
Work with top elevent of relative layout! In item below - set hint(that you want) and try to put text. May be you will have specify padding of first element of top to greate display.
Oh. And one more thing.
Maybe put to editText background background image - but is the bad to scalability.

RelativeLayout with ImageView on the right and 3 text views to the left of the image, one below another

I'm trying to use a RelativeLayout to display an image on the left side, and 3 text views, one below another, to the right of the image. Similar is explained here: http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html. The problem I'm having is that the 3rd text view does not display.
My code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="2dip">
<ImageView android:layout_width="96dip"
android:layout_height="96dip" android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" android:layout_marginRight="2dip"
android:id="#+id/myIcon" android:src="#drawable/icon" />
<TextView android:id="#+id/Line1" android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="#id/myIcon"
android:layout_alignParentRight="true" android:text="Line 1" />
<TextView android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="#id/myIcon"
android:layout_below="#id/Line1"
android:text="Line 2" android:id="#+id/Line2" />
<TextView android:layout_width="fill_parent"
android:layout_height="30dip" android:layout_toRightOf="#id/myIcon"
android:layout_below="#id/Line2"
android:id="#+id/Line3" android:text="Line 3" />
</RelativeLayout>
It's probably something really simple or obvious that I'm either doing wrong or forgetting to do, but I could really use a fresh pair of eyes taking a glance at this.
Thanks!
Try adding
android:layout_alignParentTop="true"
to your Line1 TextView. I'm not sure if this will fix your issue, but it's something to try.
Also, in regard to the '+' sign for IDs: These are for your id declarations. So, in all of your elements, you would have something like this:
android:id="#+id/SomeId"
Which is what you have. However, you do not need them for reference purposes. So
android:layout_below="#id/SomeId"
would be correct. Think of the '+' as declaring an ID and for referencing it, you do not need it.
Also: Try placing some background colors behind your views to make sure they are showing up how you expect them to. That's a debug tip that I use constantly.

EditText problem

I've got an EditText...
<EditText android:id="#+id/box" android:autoText="true"
android:layout_width="fill_parent" android:layout_height="45dip"
android:singleLine="true" android:hint="Enter" />
Is it possible to make the text only appear up on till say... 50dip from the end of the EditText?
So when typing a query it'd look like
____________________
|y query is cool |
--------------------
while typing my query is cool
You can use paddingRight in this case (assuming I understood you correctly). Here is an example:
<EditText android:id="#+id/box"
android:autoText="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="50dp"
android:singleLine="true"
android:hint="Enter"
android:text="1234567890ABCDEF-1234567890ABCDEF"/>
The best alternative is to create your own nine-patch file and decide exactly how much padding you want.
See my answer here for a quick intro: How to create android spinner without down triangle on the right side of the widget
and the official docs here:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
http://developer.android.com/guide/developing/tools/draw9patch.html
Then, you should use
android:gravity="right"
inside your EditText
im a little confused also as to what you were going for, my first thought would be to add
<EditText android:id="#+id/box"
android:autoText="true"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:singleLine="true"
android:ellipsize="start"
android:hint="Enter" />
but maybe that wasn't what you meant? you could use this in combination with the techniques listed about so that the user wouldn't be confused by the missing characters.

Categories

Resources