So I have a layout that is fairly simple and I have some weird interactions going on.
when i type on the "search_field" EditText the input works as expected. When I type in search_field2 field the input is randomly lagged and slow. Not every character is but its delayed enough to be unusable.
The only difference between the 2 editText fields is that the lagged one is nested in a relative layout. Does anyone know what could be causing it?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10sp"
>
<EditText
android:id="#+id/search_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:imeOptions="actionDone"
android:background="#FFF"
android:inputType="textPersonName"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:id="#+id/search"
android:src="#drawable/ico_search"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/search"
android:text="Top recognized"/>
<EditText
android:id="#+id/search_field2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/title"
android:ems="10"
android:imeOptions="actionDone"
android:background="#FFF"
android:inputType="textPersonName"/>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/order"
></ListView>
</LinearLayout>
We had a similar issue in an application. Unfortunately we never found any solution other than avoiding RelativeLayout. It seems that is the culprit to this, I just don't know why. Our solution was to use LinearLayout instead and then place things a bit differently. Not optimal if you like RelativeLayouts, but in our case the Linear were not too hard to use.
Related
In an Activity of my Application, the user has to submit many Strings trough an EditText and a Button. As the range of the submits can go from a minimum of 9 to a maximum of 24, I want this process to be as easy and fast as possible.
I was thinking about making the Keyboard always visible while the whole Activity content gets pushed up.
I have tried to use the following rule in the Manifest to make it push the Activity android:windowSoftInputMode="adjustResize" but it looks like it only pushes up the content with a marginBottom.
Any ideas bout how to achieve this?
EDIT:
The following is the XML code of the Layout of my Activity:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<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="wrap_content"
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="com.FET.leonardo.scurcola.NameSelection"
android:background="#e0ab18">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/whoMaster"
android:textColor="#color/white"
android:textSize="50sp"
android:layout_marginTop="50dp"
android:textAlignment="center"
android:id="#+id/whoMaster"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="#string/master"
android:ems="10"
android:textColorHint="#color/white"
android:textColor="#color/white"
android:textColorHighlight="#color/white"
android:id="#+id/names"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/next"
android:layout_marginBottom="50dp"
android:onClick="addPlayer"
android:text="#string/next"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/names"
android:textColor="#e0ab18" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"
android:id="#+id/back"
android:enabled="false"
android:onClick="removePlayer"
android:textColor="#e0ab18"
android:layout_marginBottom="50dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/names" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/finish"
android:visibility="gone"
android:text="#string/finish"
android:layout_alignParentBottom="true"
android:layout_alignEnd="#+id/names"
android:layout_marginBottom="50dp"
android:onClick="toNextActivity"
android:textColor="#e0ab18"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/zero"
android:textSize="50sp"
android:textColor="#color/white"
android:id="#+id/playersLeft"
android:layout_below="#+id/names"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
</RelativeLayout>
</ScrollView>
Apart from setting that option android:windowSoftInputMode="adjustResize", you can try using a ScrollView
Having so many fields can have some downside to your application speed - since every single element has to be drawn and that can be expensive. This will in turn affect your UI thread and could eventually cause app crashing.
Using a ScrollView, you can be able to scroll up and down through your EditText elements.
To speed up your application loading, for example if you have a lot more EditTexts, you can load half the elements/widgets when activity is loaded and once the user has started typing into the first field, load the rest.
This is an approach I have used several times and should work just fine!
Good luck and please let me know if this helps!
UPDATE
To have a scrollable view, make your root layout a ScrollView - remember it can only have 1 child.
<ScrollView
....
....
..... >
<RelativeLayout
....
....
..... >
<EditText />
...
</RelativeLayout>
</ScrollView>
So, basically you have a ScrollView as the root! That will enable you to scroll up the view and have the keyboard below or at the bottom!
this might have been asked before (and I apologise for that) but I couldn't find it so here I am.
I have a frame layout which is horizontally and vertically centered.There are two editText's in it, and I would like to arrange both of them to the center of the screen while maintaining a certain distance between the two of them.
I hope my drawing can give you an idea of what i want.
I have tried many things, but it seems it wasn't enought.Thanks for the help, and sorry for bothering!
http://oi59.tinypic.com/qxa2vm.jpg
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<EditText
android:id="#+id/editText_nume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="#string/nume" />
<EditText
android:id="#+id/editText_parola"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:text="#string/parola" />
</FrameLayout>
Use LinearLayout instead of FrameLayout. FrameLayout is designed to block out an area on the screen to display a single item.
<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" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<EditText
android:id="#+id/editText_nume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="#string/nume" />
<EditText
android:id="#+id/editText_parola"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:inputType="textPassword"
android:text="#string/parola" />
</LinearLayout>
</RelativeLayout>
As the title says, I want to stop the "ellipsis" from occurring and for it to show the whole string associated to that button. I can´t figure out why it is not displaying the string, but instead it is trimming it.
I know that "singleLine" forces a "trimming", but I want it in a single line, and not to wrap. I need the button to show it´s small string in one line, that´s all.
I have also tried using minWidth and maxWidth to no avail.
The problem occurs when viewing the layout in an Android 2.3.6 phone (Samsung Galaxy Mini).
<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"
tools:context=".MainActivity"
android:background="#drawable/background2" >
<ImageButton
android:id="#+id/quote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="24dp"
android:contentDescription="#string/quote"
android:background="#00000000"
android:padding="30dp" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/makeAMemory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:layout_marginRight="70dp"
android:text="#string/button_addMemory"
android:singleLine="true"
android:textColor="#E4F5ED"
android:background="#drawable/button_shape_shadow"
android:padding="10dp"/>
<Button
android:id="#+id/fixMemory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/makeAMemory"
android:gravity="left"
android:layout_marginTop="12dp"
android:text="#string/button_fixMemory"
android:textColor="#E4F5ED"
android:background="#drawable/button_shape_shadow"
android:padding="10dp"
android:onClick="startListViewMemoryActivity"/>
<Button
android:id="#+id/getMemory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/fixMemory"
android:gravity="left"
android:layout_marginTop="12dp"
android:text="#string/button_getMemory"
android:textColor="#E4F5ED"
android:background="#drawable/button_shape_shadow"
android:padding="10dp"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
The string is "Make memory". It´s not long at all! Any help is much appreciated.
EDITED
try adding:
android:ellipsize="none"
EDITED
In the end this is what worked:
Took out the ScrollView
Changed RelativeView from "wrap_content" to "match_parent" for the android:layout_width
The rest stays the same
It looks like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
>
I'm trying to define layout for listview item that looks like attached image (made in Photoshop). What layout(s) should I use?
i propose a LinearLayoutwith horizontal orientation first, and inside a RelativeLayoutto place other views from left / top to right / bottom using attributes : layout_alignParentTop, layout_alignParentBottom, layout_alignParentLeft, layout_alignParentRight etc ...
I would suggest using a RelativeLayout for this. Otherwise, you may up with too much nesting. I'm not going to write the layout but you should look through the RelativeLayout Docs and see all the possible properties you can give Views. You may possibly end up with child LinearLayouts also and that's ok. But I would use RelativeLayout for the parent.
If you are undecided a good thing to do is to draw it out really quick in xml how you think each might go and see with ViewGroup seems like the most efficient. Sometimes its hard to say until you get going on it by either writing the xml code or at least some pseudocode.
You only need to play now with paddings and margins.
<?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" >
<LinearLayout
android:id="#+id/gray_layout"
android:layout_width="40dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#888888"
android:layout_alignParentLeft="true"
android:gravity="center_vertical">
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AUG"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="18"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2011"/>
</LinearLayout>
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000088"
android:layout_toRightOf="#id/gray_layout"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/divider"
android:text="Title"
android:layout_marginBottom="5dp"
android:layout_alignBottom="#id/divider"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/divider"
android:text="18. aug 23:49"
android:layout_marginBottom="5dp"
android:layout_alignBottom="#id/divider"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/divider"
android:text="Short msg"
android:layout_marginTop="10dp"
android:layout_alignTop="#id/divider"/>
<ImageView
android:id="#+id/info_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#ff0000"/>
<ImageView
android:id="#+id/arrow_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_above="#id/info_button"
android:layout_toLeftOf="#id/info_button"
android:background="#00ff00"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/arrow_button"
android:layout_toLeftOf="#id/info_button"
android:layout_alignLeft="#id/arrow_button"
android:gravity="center_horizontal"
android:text="30" />
</RelativeLayout>
You can nest multiple LinearLayouts with different orientation to achieve this.
This is a follow up to this question.
Have spent days on this issue, and can't seem to get what I want. What I need very simply is this entire view to be scrollable when the keyboard pops up after touching an edittext field:
Note that this view is not scrollable, it doesn't need to be.
So when the user hits the edittext field (say the first one), it looks like this:
And if he/she chooses, the view can be scrolled to end no further that the way it looks here:
I've tried every combination of scrollview I could think of, but all it does is stretch my background image. I'm sure there is a simple solution to this, but I just can't find it. I would really be grateful to anyone who can solve this problem. Here is the XML for the layout by the way:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:orientation="vertical"
android:paddingLeft="60dp"
android:paddingTop="53dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText1"
android:layout_marginTop="3dp"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText2"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText2"
android:layout_marginTop="3dp"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText3"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/textView3"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editText3"
android:layout_marginTop="3dp"
android:text="text4" />
<ImageView
android:id="#+id/gearImage3"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignLeft="#+id/button1"
android:layout_below="#id/button1"
android:layout_marginTop="70dp"
android:clickable="true"
android:contentDescription="#string/gearDescription_string"
android:src="#drawable/gear" />
</RelativeLayout>
Kindly note the latter two images are not from the real app (photoshopped to show what I need) but the first one is from my app. Thanks.
A ScrollView only scrolls to as far as there is data. So simply adding a ScrollView should just fix your problem. Add this to the start of your xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
and then obviously add this at the bottom, after everything else:
</ScrollView>
I use this in my app and when the keyboard shows, I can still scroll to the bottom of the page. If your fields as shown in screenshot 1, are not longer than one normal phone page, it won't scroll anyway. It will only scroll when you have the keyboard up as it can't then see the whole screen.
Hope this helps!