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.
Related
I have a problem with the FancyCoverFlow which extends Gallery:
https://github.com/davidschreiber/FancyCoverFlow
I want to center the selected Image of the FancyCoverFlow. On my 5" Android 4.2 Device it works perfectly. But on my 3.7" Android 2.2 the selected Image has an Off-Set to the left.
(I prepaired Images, but I can't post them until I does have 10 Reputations xD)
My FancyCoverFlow Item in XML looks like this:
<package.FancyCoverFlow
android:id="#+id/fancyCoverFlow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
fcf:maxRotation="55"
fcf:scaleDownGravity="0.8"
fcf:unselectedAlpha="0.3"
fcf:unselectedSaturation="0.0"
fcf:unselectedScale="0.2" >
</package.FancyCoverFlow>
The layout of the item I'm displaying in this FancyCoverFlow looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
>
<ImageView
android:id="#+id/horizontal_player_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitCenter"
android:layout_above="#+id/relatLayout"
/>
<RelativeLayout
android:id="#+id/relatLayout"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_above="#+id/horizontal_player_name">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginLeft="5dp"
android:src="#drawable/drinkplayeritem"
android:layout_centerVertical="true"
android:adjustViewBounds="true"/>
<package.BrushTextView
style="#style/BrushFont"
android:id="#+id/horizontal_drink_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_centerVertical="true"
android:text=""
android:gravity="left"
android:layout_toRightOf="#+id/imageView1"
/>
<package.BrushTextView
style="#style/BrushFont"
android:id="#+id/horizontal_false_card_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_centerVertical="true"
android:text=""
android:gravity="right"
android:layout_toLeftOf="#+id/imageView2"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:src="#drawable/cardsplayeritem" />
</RelativeLayout>
<package.BrushTextView
style="#style/BrushFont"
android:id="#+id/horizontal_player_name"
android:layout_width="100dp"
android:layout_height="20dp"
android:textColor="#android:color/white"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:textSize="15sp"
/>
</RelativeLayout>
I already tried center everything I've found :D ImageViews (FitCenter) etc...
Nothing worked. It is so stupid that it works on my newer Device but on the older one not..
Hope someone can help me and maybe had the same issue.
EDIT 1:
Does it results of the deprecated class Gallery? But if so, why does it work on my newer device? :D
Thanks!
eclipse shows me an error when I'm referring to a element that is declared later. How can I solve this or is there any kind of work around. Here is the part of my xml-layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:padding="5dp">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#id/imageView1" <!-- error -->
android:layout_alignParentLeft="true"
android:layout_alignTop="#id/imageView1" <!-- error -->
android:layout_centerVertical="true" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/checkBox1"
android:src="#drawable/folder" />
I want the ImageView to be to the right of the checkbox, but I also want the checkBox to be as "high" as the ImageView (the checkbox should be still a square)
regards
#kalyan pvs....it is ok but you should not call each time with "#+id" which means you are creating new instance each time. This is wrong way of referring to an item in relative layout. In this, rendering errors will come when you are referring to a view which will be created after the present view. The right way of calling reference is #id only.
Just swap the CheckBox and the ImageView and remove android:layout_toRightOf="#+id/checkBox1" from the ImageView (in order to avoid a circular reference):
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:src="#drawable/folder"
/>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#id/imageView1"
android:layout_centerVertical="true"
/>
Otherwise, the CheckBox can't refer the ImageView's id, since it hasn't been created yet
[EDIT]
An even better way to do that is incorporating the ImageView into the CheckBox, as a compound drawable:
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:drawableRight="#drawable/folder"
android:layout_drawablePadding="10dp"
/>
Note that now the image is on the right side of the checkbox.
This is a best practice.
Declaring a View later is not a problem, Try this, Reduced some lines of your code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:padding="5dp" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/checkBox1"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
Something like this works for me:
<?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="wrap_content"
android:background="#FFFFFF"
android:padding="5dp">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:layout_centerVertical="true" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/checkBox1"
android:src="#drawable/folder" />
</RelativeLayout>
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 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.