I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget30"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/v_fundo"
>
<ImageView
android:id="#+id/imageView1"
android:layout_height="wrap_content"
android:src="#drawable/v_titulo"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true">
</ImageView>
<RelativeLayout android:layout_height="wrap_content" android:id="#+id/relativeLayout2" android:layout_width="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true">
<ImageView android:id="#+id/widget32" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="#drawable/v_personagem"> </ImageView>
<Button android:layout_height="wrap_content" android:background="#drawable/v_balao" android:layout_width="wrap_content" android:id="#+id/lastComicButton"></Button>
</RelativeLayout>
<ImageView android:src="#drawable/v_transparente" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/imageView2" android:layout_alignParentBottom="true"></ImageView>
<RelativeLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/relativeLayout1" android:background="#drawable/funcoes_fundo" android:layout_above="#+id/imageView2" android:layout_alignLeft="#+id/imageView2" android:layout_alignRight="#+id/imageView2">
<Button android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:id="#+id/button2"
android:text="Yes, we can!"
android:background="#drawable/funcoes_1">
</Button>
<Button android:layout_height="65dp"
android:layout_alignRight="#+id/button2"
android:layout_alignLeft="#+id/button2"
android:layout_width="250dp"
android:id="#+id/button1"
android:layout_below="#+id/button2"
android:background="#drawable/funcoes_2">
</Button>
</RelativeLayout>
The button with id button2 (android:id="#+id/button2") shows the text fine in the Emulator and on the Milestone II.
However, when I put the .apk into the Motorola Defy, the image background of the button hides its text ("Yes, we can!"). I am sure of that because if I don't show the background (by deleting the line android:background="#drawable/funcoes_1"), the text is shown fine in the button.
Does anybody have any clue on why the background image of the Button is hiding its text in some devices (like the Motorola Defy)?
Thank you in advance!
android:layout_alignRight="#+id/button2"
android:layout_alignLeft="#+id/button2"
android:layout_below="#+id/button2"
These should all be set to either "true" or "false". These properties are used to determine in a RelativeLayout the "relative" gravity/alignment of a member.
Declaring android:id="#+button2" once is enough.
What is likely happening is the device it doesn't work on has an older or different version of Android that is not tolerant of this error.
Hope this helped.
Related
Hello I have a simple application that uses a checklist on of the layouts. Weirdly, the CheckBox works great on my Galaxy phone (ANDROID V5.0.1) but for some reason when I use the same application on the tablet(ANDROID V4.2.2) the CheckBox disappears when clicked, any ideas would be helpful thank you!
XML:
<?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:orientation="vertical"
android:padding="6dip"
android:background="#FFFFFF">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="20dp"
android:buttonTint="#0870f8" />
<TextView
android:id="#+id/code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/imageView2"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView2"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp" />
</RelativeLayout>
I just guess because i don't have a tablet here and you didn't provide any information about android version.
I don't think that your checkbox just disappears, try to change background of RelativeLayout to any color (like red or blue) to check if it really disappear.
Hope this helps.
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"
>
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
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
I need to place a button at the bottom of screen, leaving some space below it.
In other words I am using these two attributes for my button -
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
but the margin attribute wont work when I use alignParentBottom and the button sticks at the bottom only. Please tell me how to place it a little above the bottom .
Here's the xml
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="#drawable/board"
android:layout_marginLeft="10dp"
android:layout_marginRight="60dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Type of Lesion"
android:textColor="#8B0A50"
android:layout_marginTop="40dp"
android:id="#+id/disease_listheader_textview"
android:drawableBottom="#drawable/underline"/>
<ListView
android:id="#+id/disease_listview"
android:layout_below="#id/disease_listheader_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#drawable/divider"
android:layout_marginLeft="40dp"
android:layout_marginBottom="50dp"
android:cacheColorHint="#00000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/disease_search_button"
android:layout_centerHorizontal="true"
android:background="#drawable/disease_search_btn"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
just make change in relative layout height attribute value to fillparent like
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
.................../>
hope this help you
Can you try this?
Replace the Button tag with the one mentioned below. I am trying to wrap the button in another dummy layout
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:paddingBottom="20dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/disease_search_button"
android:background="#drawable/disease_search_btn"
android:layout_marginBottom="20dp"/>
</LinearLayout>
This runs just the way you wanted
<RelativeLayout android:id="#+id/relativeLayout1" android:layout_width="match_parent" android:layout_height="fill_parent">
<Button android:text="Button" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="20dip"></Button>
</RelativeLayout>