Changing Buttons from Relative Layout to Linear Layout weird side-effects - android

The strangest thing happened to me today and caused hours of frustration and anger-management issues.
I had a working Android slideshow application. However, I was unhappy with the buttons (which were in a Relative Layout), and moved them to a Linear Layout. However, when running my application, the behavior of the buttons got swapped around (ie Button 1 did Button 2's work and vice-versa). I was able to remedy this by changing the id of ONE of the buttons, not all (that didn't work). Also related to this, was that my application started crashing when I switched orientation. It had worked previously when I had the Relative Layout. (I am using a Handler to change the UI for the slideshow)
I was unable to solve this issue, so I reverted to my Relative Layout, but I would like to know how this could have happened in the first place.
The layout that works:
<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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:contentDescription="#string/imageView"
android:scaleType="centerInside"
android:src="#drawable/image1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageButton
android:id="#+id/startStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/startStop"
android:src="#drawable/ic_menu_slideshow" />
<ImageButton
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false"
android:layout_toRightOf="#+id/startStop"
android:contentDescription="#string/next"
android:src="#drawable/ic_media_next" />
<ImageButton
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_toLeftOf="#+id/startStop"
android:contentDescription="#string/previous"
android:src="#drawable/ic_media_previous" />
</RelativeLayout>
The code that causes problems:
<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="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:contentDescription="#string/imageView"
android:scaleType="centerInside"
android:src="#drawable/image1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#30eee9e9" >
<ImageButton
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/previous"
android:src="#drawable/ic_media_previous" />
<ImageButton
android:id="#+id/bla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/startStop"
android:src="#drawable/ic_menu_slideshow" />
<ImageButton
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/next"
android:src="#drawable/ic_media_next" />

I had the same problem but with Relative Layout as parent & Linear Layout as child layout I took four imagebuttons
PLAY
SCORE
HELP
QUIT
And buttons functionality was shifted to one below next i.e. when I pressed PLAY nothing happened when pressed SCORE Game started playing when clicked HELP showed me score and so on.. I put my whole night for solving the problem but nothing happened I shutted off dam thing tried to watch movie but for a while I was getting boared watching it I started Eclipse again and the magic that it was working so fine. Dont know But Rebuild & Clean has solved my problem as DeeV said

Related

All texts in the app are gone after a while

This is probably the weirdest thing it ever happened to me. I inherit this code from another developer and I can't figure out which is the problem.
The app uses the sherlocknabvar and it also has a screen with a mapfragment where you can move a pin around and once the map is settled it calls several APIs to get some info about your position. The rest of the activities are pretty normal, nothing fancy about them. The map activity is quite complex though.
This is the error I have... weirdest thing is that it only happens sometimes, so it's not easy to reproduce it but I still can see it happen from time to time.
After playing with the map for a while (moving the pin, zooming in and out and so on) if I go back to the main activity (by clicking a home button on the navbar or by clicking the back button) all the texts in my app are gone in all the activities. I can see all the different layouts with images and colours but all the texts are completely gone. The only way to have them back is by restarting the app.
Looking at the Android Device Monitor (in case was some memory leak) everything looked pretty stable (28016K/33287K as max) and even worst, I can reproduce that error in an old Sony Xperia but also in a new brand S5.
EDIT
I found out that the texts where not missing, the color was changing to transparent for some reason that I still don't get. I disabled the hardware acceleration and it works but I'm still wondering what the problem could be and why that changed fixed it.
This is one of the layouts I'm having problems with, all the TextViews just change to transparent without any reason. It happens to the TextViews that have an 'static' text and also to the ones that I change the text dynamically.
<?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:fillViewport="true"
android:background="#drawable/new_bg_background_app"
>
<ScrollView
android:layout_alignParentTop="true"
android:layout_above="#+id/anc_button"
android:fadeScrollbars="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/anc_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="#string/lb_confirmed"
android:textColor="#color/orange"
android:textAppearance="#style/Font50PX"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ic_confirmed"
android:layout_marginTop="15dp"
android:src="#drawable/new_ic_active"
android:layout_below="#+id/anc_title"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/lb_pick_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:layout_below="#+id/ic_confirmed"
android:text="#string/lb_your_pick_up"
android:textAppearance="#style/Font28PX"
android:textColor="#color/text_gray" />
<TextView
android:id="#+id/txt_passengers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/lb_pick_up"
android:text="5 Passengers"
android:textAppearance="#style/Font50PX"
android:textColor="#color/white"/>
<TextView
android:id="#+id/lb_from"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="6dp"
android:layout_below="#+id/txt_passengers"
android:text="#string/lb_from"
android:layout_marginTop="15dp"
android:textAppearance="#style/Font28PX"
android:gravity="center"
android:textColor="#color/text_gray" />
<TextView
android:id="#+id/txt_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="60"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:layout_below="#+id/lb_from"
android:textAppearance="#style/Font50PX"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/txt_post_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="60"
android:gravity="center"
android:layout_below="#+id/txt_address"
android:textAppearance="#style/Font45PX"
android:textColor="#color/text_gray"
/>
<TextView
android:id="#+id/lb_at"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_post_code"
android:text="#string/lb_at"
android:layout_marginTop="15dp"
android:textAppearance="#style/Font28PX"
android:gravity="center"
android:textColor="#color/text_gray" />
<TextView
android:id="#+id/txt_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/lb_at"
android:textAppearance="#style/Font50PX"
android:text="9:00 AM Today"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/txt_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_time"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="#string/lb_mini"
android:textAppearance="#style/Font26PX"
android:textColor="#color/text_gray"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_note"
android:layout_marginTop="10dp"
android:gravity="center"
>
<TextView
android:id="#+id/lb_reference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lb_reference"
android:layout_marginTop="15dp"
android:textAppearance="#style/Font32PX"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/txt_reference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/lb_reference"
android:layout_marginLeft="4dp"
android:layout_marginTop="17dp"
android:textAppearance="#style/Font28PX"
android:textColor="#color/white"
/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<Button
android:id="#+id/anc_button"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="#string/lb_done"
android:background="#drawable/new_btn_orange"
android:layout_margin="5dp"
android:onClick="onDone"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
This issue was fixed after disabling the hardware acceleration in the manifest just for the activity I was having the problem with
android:hardwareAccelerated="false"

Android Button stop "ellipsis" its test when singleLine="true"

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"
>

Android Button text not centered when using API 17 for rendering

In the graphical view of layout, when I choose API 15 or lower from the button shown in the image below, the text in the encircled buttons looks fine.
When I choose API 17, the text is displaced even though the xml code is same. Changing the button padding does not help.
Is this just a problem with Eclipse or is it possible that new versions of android may see this displaced text?
What's the workaround to fix this?
XML code:
<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=".HomeActivity" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="3dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="#drawable/label" />
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/linearLayout1"
android:layout_marginTop="20dp"
android:text="#string/about_title"
android:textSize="20sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignRight="#+id/linearLayout1"
android:layout_below="#+id/textView1"
android:layout_marginTop="5dp"
android:text="#string/temp" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignRight="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="20dp"
android:baselineAligned="false" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/news" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tournaments" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/results" />
</LinearLayout>
android:gravity="center" did not help
I restarted eclipse twice. Strangely it did not help in the first restart but it looked fine after the second one. Also, its working fine on device.
Apologies for the question, I must have waited before posting the question.
Not sure if the default style for Buttons changed in API17... possibly...
Anyway, adding android:gravity="center" should be fixing this for you.
i don't know i faced this problem check restart a eclipse.. and check..
adding android:gravity="center" should be fixing this for you

Cannot completely fill the screen with RelativeLayout and cannot resize on Keyboard opening

So here is my XML. I am trying to fill the whole screen and when I view it in Eclipse, it fills the whole screen. However, when I open it on my phone, everything is smaller and there are views overlaying. I don't know what's going on.
<?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="fill_parent" >
<TextView
android:id="#+id/front"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Front"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/frontInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/front"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/frontInput"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Back"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/backInput"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/back"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="#+id/background"
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/backInput"
android:layout_marginTop="44dp"
android:text="Background"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/colors_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/backInput"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:layout_toRightOf="#+id/background"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/colors_spinner" >
<Button
android:id="#+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="#+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
this is what it looks in Eclipse.
But I get this:
Another thing is that when I open the keyboard my view does not rezise so you can see everything but smaller so you can see what you are typing etc... I have added the android:windowSoftInputMode="adjustResize" for the specific activity but nothing is happening... Any ideas? Thanks guys...
If you use adjustResize it will resize everything to fit as best it can. The other option is adjustPan, which will scroll the window so that the focused EditText will be in the view and the caret visibile. Other than that there's no real way to control things.
In your case you have some exact heights in there, so it won't work well with a resize, since you can't shrink an exact height.
Also, never trust how things look in Eclipse. Its an attempt to lay things out that shares no code with how Android really does things, it should be viewed as an estimate. Real layouts may end up looking significantly different, especially for complex layouts.

android can android:gravity do this?

Searched all day and came up with a poor solution i think.
i want three ImageButton placed on the right sida of the screen.
Not centered but just above center position..
With the code below i get the result i want but,
If the user have a bigger screen they will not have this position right?
I have tried the android:gravityall day and all i can do with it is
to center the three buttons very nicely.
What should i use to make the three buttons always stay at the positions that
they are on the image belove.
i have the button image in 3 different sizes in hdpi,mdpi,xhdpi folder.
<RelativeLayout
android:id="#+id/rightRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageButton
android:id="#+id/btn_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="A"
android:src="#drawable/drawer_1"
android:background="#android:color/transparent"
android:layout_alignParentRight="true"
/>
<ImageButton
android:id="#+id/btn_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="B"
android:src="#drawable/drawer_1"
android:background="#android:color/transparent"
android:layout_alignParentRight="true"
android:layout_below="#+id/btn_A"
/>
<ImageButton
android:id="#+id/btn_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="C"
android:src="#drawable/drawer_1"
android:background="#android:color/transparent"
android:layout_alignParentRight="true"
android:layout_below="#+id/btn_B"
/>
</RelativeLayout>
Picture of the three buttons placed on the right side, and my daughter of course.
One option would be to put all three buttons within a LinearLayout (for simplicity's sake) and then set the layout of this container programmatically.
You can see the size of the screen using getResources().getDisplayMetrics().heightPizels and then set the top margin accordingly.
You could add a LinearLayout inside the RelativeLayout, and then use the following properties on the LinearLayout:
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
EDIT: Ok, I've done some testing and found a way of doing what you want without the use of styling it programatically, here's the xml:
<RelativeLayout
android:id="#+id/rightRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="80dip"
>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true">
<ImageButton
android:id="#+id/btn_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:src="#drawable/icon"
android:background="#android:color/transparent"
/>
<ImageButton
android:id="#+id/btn_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
android:src="#drawable/icon"
android:background="#android:color/transparent"
/>
<ImageButton
android:id="#+id/btn_C"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:src="#drawable/icon"
android:background="#android:color/transparent"
/>
</LinearLayout>
</RelativeLayout>

Categories

Resources