I made an application for android, and it was loading fine in the emulator and phone, and then I made some minor changes like shifting the position of text View elements in the layout with help of "Graphical Layout" editing option in Eclipse. and after that the application no longer starts, it just loads with a blank activity and in 2-3 seconds crashes.
The layout that I am using looks like this currently (and this is the crashing state of layout):
<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"
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=".BMI" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_alignLeft="#+id/textView2"
android:text="#string/weight"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginLeft="15dp"
android:layout_marginTop="30dp"
android:text="#string/button1_text" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_toRightOf="#+id/textView3"
android:ems="4"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_below="#+id/editText2"
android:ems="4"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignParentTop="true"
android:text="#string/bmi"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_alignParentTop="true"
android:text="#string/default_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:layout_marginLeft="17dp"
android:text="#string/height"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_toRightOf="#+id/editText1"
android:text="#string/button2_text" />
</RelativeLayout>
Try cleaning and rebuilding the project by going to "Project --> Clean..." then run the app again. After making changes in Eclipse to the layout, sometimes Eclipse doesn't "get" the changes right away so you end up with a goofy ClassCastException. A cleaning usually fixes this.
If this doesn't solve your problem then please post the logcat from the crash but this should do the trick.
I had several problems with Android build tool on both Eclipse and IntelliJ. Usually result in xml file doesn't get updated or shift up or down by a line or two. Usually, by rebuilding the project or restarting your IDE would fix this problem.
// try this
<?xml version="1.0" encoding="utf-8"?>
<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"
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=".BMI" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_alignLeft="#+id/textView2"
android:text="#string/weight"
android:textAppearance="#android:style/TextAppearance.Medium" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginLeft="15dp"
android:layout_marginTop="30dp"
android:text="#string/button1_text" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_toRightOf="#+id/textView3"
android:ems="4"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_below="#+id/editText2"
android:ems="4"
android:inputType="numberDecimal" >
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignParentTop="true"
android:text="#string/bmi"
android:textAppearance="#android:style/TextAppearance.Medium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_alignParentTop="true"
android:text="#string/default_text"
android:textAppearance="#android:style/TextAppearance.Medium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:layout_marginLeft="17dp"
android:text="height"
android:textAppearance="#android:style/TextAppearance.Medium"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_toRightOf="#+id/editText1"
android:text="#string/button2_text" />
</RelativeLayout>
Related
I have a problem with RelativeLayout. In design view I can see my Layout works perfect, but in runtime one EditText goes down from the screen.
Here is some code of my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvInicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="#string/dialog_titulo"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPrimero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="85dp"
android:text="#string/dialog_max"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tvPrimero"
android:layout_alignParentEnd="true"
android:ems="10"
android:hint="#string/dialog_etMax"
android:inputType="number"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/etMinimo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="151dp"
android:ems="10"
android:hint="#string/dialog_etMin"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvSegundo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/etMinimo"
android:text="#string/dialog_maxmin"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo2"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/tvSegundo"
android:ems="10"
android:hint="#string/dialog_etMax"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvTexto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/etTexto"
android:layout_alignParentStart="true"
android:text="#string/diaog_textoTitulo"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etTexto"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="180dp"
android:ems="10"
android:hint="#string/diaog_etTextoTitulo"
android:inputType="textPersonName"
android:layout_alignParentRight="true" />
<LinearLayout
android:layout_width="360dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/btnCancelar"
android:layout_width="176dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="19dp"
android:layout_toLeftOf="#+id/etTexto"
android:layout_toStartOf="#+id/etTexto"
android:background="#drawable/boton_redondeado2"
android:text="#string/iniciar_sesion_cancelar"
android:textColor="#android:color/background_light" />
<Button
android:id="#+id/btnGuardar"
android:layout_width="178dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/btnCancelar"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:background="#drawable/boton_redondeado"
android:text="#string/diaog_guardar"
android:textColor="#android:color/background_light" />
</LinearLayout>
See here
Run time view look like this
Can someone help me because I'm desperate. My English is bad, so I accept edits
When using RelativeLayout, instead of using
android:layout_alignParentBottom="true"
android:layout_marginBottom="180dp"
like you are doing in the EditText with with id #+id/etTexto, you can simply write this code: android:layout_below="#id/etMaximo2"
You can even place some android:layout_marginTop if you want to add more space between the two Views.
P.S. For testing in the design view, know that you can change the dimensions of the device you're testing, so you can see in the "Preview" window what it would look like on device with different screen sizes. You can change this in the top toolbar of the preview window.
I hope this helps you! :)
Give this id to the LinearLayout:
android:id="#+id/layout"
and add this attribute to etTexto:
android:layout_above="#+id/layout"
also adjust the bottom margin as you like.
Try to delete android:layout_alignParentEnd="true" and then clean your project after the clean, run again.
Make sure that your Relative Layout is closed right after the linear ends
</LinearLayout>
</RelativeLayout>
Does it work now?
I used this xml and it worked on a Nexus 5 emulator
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvInicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="TEST"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPrimero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="85dp"
android:text="test"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tvPrimero"
android:layout_alignParentEnd="true"
android:ems="10"
android:hint="test"
android:inputType="number"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/etMinimo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="151dp"
android:ems="10"
android:hint="test"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvSegundo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/etMinimo"
android:text="test"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo2"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/tvSegundo"
android:ems="10"
android:hint="test"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvTexto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/etTexto"
android:layout_alignParentStart="true"
android:text="test"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etTexto"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="180dp"
android:ems="10"
android:hint="this should stay right here"
android:inputType="textPersonName"
android:layout_alignParentRight="true" />
<LinearLayout
android:layout_width="360dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/btnCancelar"
android:layout_width="176dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="19dp"
android:layout_toLeftOf="#+id/etTexto"
android:layout_toStartOf="#+id/etTexto"
android:background="#color/colorPrimary"
android:text="button"
android:textColor="#android:color/background_light" />
<Button
android:id="#+id/btnGuardar"
android:layout_width="178dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/btnCancelar"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:background="#color/colorAccent"
android:text="button"
android:textColor="#android:color/background_light" />
</LinearLayout>
</RelativeLayout>
Maybe you should try putting it below EditText that is above it?
Remove
android:layout_alignParentBottom="true"
android:layout_marginBottom="180dp"
Add
android:layout_below="#+id/etMaximo2"
Result
<EditText
android:id="#+id/etTexto"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/etMaximo2"
android:ems="10"
android:hint="#string/diaog_etTextoTitulo"
android:inputType="textPersonName"
android:layout_alignParentRight="true" />
Then set some top margin android:layout_marginTop="{some value}dp" to make it look like you want.
This happened yesterday when i was replacing a few elements in my XML. When I went to my main class, I saw that all references to R had been marked red, and I was told that R could not be resolved to a variable. At first, I tried to rebuild and clean up my project, but that didn't work, so I am assuming that the issue lies in the XML file I recently edited, however I do now know where the issue would lie. And yes, I did make sure android.R was not being imported.
A few additional details:
I am using Android 5.0 (API 21)
The R issues do not appear in my other class files, which reference R.
Here is the XML file in question:
<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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp"
android:text="#string/rye"
android:textColor="#888888"
android:textAppearance="?android:textAppearanceLarge" />
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:isIndicator="false"
android:numStars="5"
android:stepSize="1" />
<Button
android:id="#+id/dropDownButton"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignBottom="#+id/ratingBar1"
android:layout_toRightOf="#+id/ratingBar1"
android:onClick="dropDown"
android:text=">"/>
<RelativeLayout
android:id="#+id/dropDownLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/textView2"
android:visibility="gone" >
<TextView
android:id="#+id/testTV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Testing dropdown" />
</RelativeLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tipTitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888"
android:layout_below="#+id/quizFragment"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<FrameLayout
android:id="#+id/quizFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/dropDownButton" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/people_dining_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888"
android:layout_below="#+id/seekBar3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/subtotalTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/subtotal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888"
android:layout_below="#+id/seekBar2"
android:layout_alignLeft="#+id/seekBar2"
android:layout_alignStart="#+id/seekBar2" />
<TextView
android:id="#+id/totalTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/subtotalText"
android:layout_below="#+id/subtotalText"
android:layout_marginTop="10dp"
android:text="#string/total"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888" />
<TextView
android:id="#+id/totalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/subtotalText"
android:layout_alignRight="#+id/subtotalText"
android:layout_below="#+id/totalTitle"
android:focusable="false"
android:padding="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffff000c" />
<EditText
android:id="#+id/subtotalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/subtotalTitle"
android:ems="10"
android:hint="SUBTOTAL"
android:inputType="numberDecimal"
android:padding="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ff0000"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/seekBar2"
android:layout_alignEnd="#+id/seekBar2">
</EditText>
<TextView
android:id="#+id/eppTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/totalText"
android:layout_below="#+id/totalText"
android:layout_marginTop="10dp"
android:text="#string/epp"
android:textColor="#888888"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:id="#+id/eppText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/eppTitle"
android:layout_alignRight="#+id/totalText"
android:layout_below="#+id/eppTitle"
android:focusable="false"
android:padding="2dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/buttonDone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/eppText"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:onClick="done"
android:text="#string/done"
android:textStyle="bold" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/seekBar2"
android:layout_below="#+id/TextView02"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/seekBar3"
android:layout_below="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
I am not able to see any issues in this xml file . Can you also post the code for the class file where you are using it and check if you're not using android.r and using com.yourapp.r . This might be the case. Could you post the class also
When I am trying to look at my graphical layout this message appears in the error log:
activity_main.xml: Circular dependencies cannot exist in RelativeLayout.
How would I go about correcting this so my code will work correctly?
I have changed around the alignParentLeft and set them to true. I have also messed around with the align_above and align_below which hasn't helped. I'm not sure what my problem is.
Here is my 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"
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=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="57dp"
android:text="Number of cups" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:layout_marginRight="23dp"
android:layout_toRightOf="#+id/textView1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<CheckBox
android:id="#+id/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/cream"
android:layout_alignParentLeft="true"
android:layout_marginBottom="20dp"
android:text="To Go" />
<CheckBox
android:id="#+id/cream"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/sugar"
android:layout_alignParentLeft="true"
android:layout_marginBottom="15dp"
android:text="Leave room for cream" />
<CheckBox
android:id="#+id/sugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/drinks"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Leave room for sugar" />
<RadioGroup
android:id="#+id/drinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sugar"
android:layout_above="#+id/flavoring"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" >
<RadioButton
android:id="#+id/coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee($2.50)" />
<RadioButton
android:id="#+id/cappuccino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Cappucino($4.50)" />
<RadioButton
android:id="#+id/espresso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Espresso($4.50)" />
<RadioButton
android:id="#+id/latte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latte($4.50)" />
<RadioButton
android:id="#+id/iced_latte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Iced Latte($5.00)" />
</RadioGroup>
<TextView
android:id="#+id/flavoring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/chocolate"
android:layout_alignParentLeft="true"
android:layout_marginTop="57dp"
android:text="Flavoring" />
<CheckBox
android:id="#+id/chocolate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/cherry"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Chocolate" />
<CheckBox
android:id="#+id/cherry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/vanilla"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Cherry" />
<CheckBox
android:id="#+id/vanilla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cherry"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Vanilla" />
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="#+id/editText1"
android:layout_alignParentBottom="true" >
</ScrollView>
</RelativeLayout>
These are your problems
<CheckBox
android:id="#+id/sugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/drinks"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Leave room for sugar" />
<RadioGroup
android:id="#+id/drinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sugar"
android:layout_above="#+id/flavoring"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" >
You are telling sugar to be above drinks and for drinks to be below sugar. You can only do one of these or they get into an infinite circle. So remove android:layout_below="#+id/sugar" from drinks RadioGroup.
I don't see yet if you have this anywhere else but if you do then you will need to fix those, also. You can't tell a View to be above another and tell that View to be below the same View...same with left and right.
Edit found another
<CheckBox
android:id="#+id/cherry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/vanilla"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Cherry" />
<CheckBox
android:id="#+id/vanilla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cherry"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Vanilla" />
You have the same thing going on here. You will need to remove the above or the below from one of these.
I am new to android.Wen I run this apk file in my phone,it runs and wen I rotate for a horizontal view,it shows only half a page and if I try to scroll,it doesnt scroll.I tried a lot using ScrollView.It is not getting Implemented.the error wch occurs is :"activity_main.xml: ScrollView can host only one direct child".Can someone suggest me how to solve it??
<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"
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=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_centerHorizontal="true"
android:text="LOGIN"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:layout_marginTop="49dp"
android:text="Username"
android:textSize="20sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/editText3"
android:layout_marginTop="17dp"
android:text="Password"
android:textSize="20sp" />
<TextView
android:id="#+id/link_to_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button1"
android:layout_below="#+id/button1"
android:layout_marginTop="14dp"
android:gravity="center"
android:text="Forgot Password"
android:textColor="#0b84aa"
android:textSize="20dip" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="26dp"
android:layout_toLeftOf="#+id/textView1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView1"
android:layout_alignLeft="#+id/editText4"
android:ems="10"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="42dp"
android:layout_toLeftOf="#+id/textView1"
android:ems="10" />
<EditText
android:id="#+id/editText4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_marginLeft="100dp"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText3"
android:layout_below="#+id/editText4"
android:layout_marginTop="23dp"
android:background="#9ACD32"
android:text="Log In" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/imageView2"
android:scaleX="1.5"
android:scaleY="1.5"
android:src="#drawable/igs_login" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="21dp"
android:layout_toRightOf="#+id/button1"
android:src="#drawable/igs" />
The error says it very clearly ScrollView can host only one direct child. That means when you are using ScrollView you should consider creating a layout which holds all views in it and add your ScrollView as it's parent. For example :
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
//ADD YOUR VIEWS ONLY HERE
</RelativeLayout>
</ScrollView>
You layout should look like this! Instead of RelativeLayout, you can use whenever layout you want, but just remember: All views should be added in one layout!
ScrollView can host only one child, such as RelativeLayout or LinearLayout (or any other View extending VIewGroup, so your implementation should be something like this:
<ScrollView>
<LinearLayout>
here you can put how many Views you need
</LinearLayout>
</ScrollView>
In the android preview screen in eclipse, I see the following: https://dl.dropboxusercontent.com/u/63060352/379d2a92a0b1f8300d25ff15bf5bcbae.png
But when I run the app on my phone, the "Feedback" and "Suggestions or feedback? Let us know." textViews are not there, but the others are. I am confused why these aren't showing when I run the app on my phone and on the emulator.
Here's my XML:
<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"
android:background="#drawable/info_screen_high"
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=".InfomenuActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="154dp"
android:layout_toRightOf="#+id/textView1"
android:src="#drawable/star_rating_medium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="149dp"
android:text="Rate It"
android:textColor="#FFFFFF"
android:textSize="32sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/imageView1"
android:layout_marginTop="14dp"
android:text="Rate this app in the market!"
android:textSize="17dp"
android:textColor="#B6B6B4" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="20dp"
android:text="Tell a friend"
android:textColor="#FFFFFF"
android:textSize="29dp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_centerVertical="true"
android:text="Spread the word about the app!"
android:textColor="#B6B6B4"
android:textSize="17dp" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_below="#+id/textView4"
android:layout_marginTop="285dp"
android:text="Feedback"
android:textColor="#FFFFFF"
android:textSize="29dp" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView5"
android:layout_below="#+id/textView5"
android:text="Suggestions or feedback? Let us know."
android:textColor="#B6B6B4"
android:textSize="18dp" />
</RelativeLayout>
If anyone could help me out, that would be much appreciated!
You have android:layout_marginTop="285dp" in the textView5, is too much! You can put something like 30dp and it is going to work
have you tried to remove these paddings, might be this problem.
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
can u show us a snapshot of this screen appearing in device.