I am trying to put a ViewAnimator above a button in RelativeLayout but it does not let me. Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewAnimator
android:id="#+id/show_picture_animator_VA"
android:layout_alignParentTop="true"
android:layout_above="#id/show_picture_hold_BTN"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ViewAnimator>
<Button android:id="#+id/show_picture_hold_BTN"
android:text="HOLD"
android:textColor="#000000"
android:background="#drawable/hold_button_shape"
android:layout_width="#dimen/show_picture_hold_button_widht"
android:layout_height="#dimen/show_picture_hold_button_height"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
This gives me this error:
Error:(7, -1) android-apt-compiler: [] --\res\layout\show_picture.xml:7: error: Error: No resource found that matches the given name (at 'layout_above' with value '#id/show_picture_hold_BTN').
Can someone please help me :)
Ids are added in the order they are listed (the ones with the #+id values). show_picture_hold_BTN is defined (android:id="#+id/show_picture_hold_BTN") after it as referenced in the ViewAnimator.
Since this is a relative layout, the align values are what order them visually; swap the order of the two views in XML and you're good.
<Button
android:id="#+id/show_picture_hold_BTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="HOLD"
android:textColor="#000000" />
<ViewAnimator
android:id="#+id/show_picture_animator_VA"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/show_picture_hold_BTN"
android:layout_alignParentTop="true">
</ViewAnimator>
Related
I downloaded sample android carousel demo source code in the below link http://www.codeproject.com/Articles/146145/Android-3D-Carousel#xx4884593xx
The main.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pj="http://schemas.android.com/apk/res/carousel.main"
xmlns:bm="carousel.main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/back"
android:orientation="vertical" >
<TextView
android:id="#+id/selected_item"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:background="#1E1921"
android:text="text"
android:textColor="#A85E4F"
android:textStyle="normal"
android:visibility="gone" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="top"
android:padding="5dip" >
<carousel.Carousel
android:id="#+id/carousel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animationDuration="200"
pj:Items="#array/entries"
pj:SelectedItem="0"
pj:UseReflection="true" />
</LinearLayout>
</LinearLayout>
However I'm now getting the following errors:
Description Resource Path Location Type
error: No resource identifier found for attribute 'UseReflection' in package 'carousel.main' main.xml
Suspicious namespace: should start with http:// main.xml
Each time I try and clean the project it deletes the R.file. I've tried changing the package name, and pasting all the contents again but that hasn't solved the problem.
I found where the problem was.
In the root of the xml:
xmlns:pj="http://schemas.android.com/apk/res/package_with_calling_class"
xmlns:bm="package_with_calling_class"
package_with_calling_class = the class which might be the main activity where the onCreate() is being called. In my case it was platinum.platinumstars
setContent(R.layout.main)
I am creating a layout in XML, and I have noticed this very strange occurrence. It has never happened before, but lately it's been getting on my nerves. I kind of want to abandon Eclipse and find a better IDE because of it.
Here is my layout:
<?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:orientation="vertical" >
<EditText
android:id="#+id/action_search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="kkm" >
</EditText>
<ListView
android:id="#+id/actions_list"
android:layout_width="90dp"
android:layout_height="match_parent"
android:layout_above="#id/cancel_action_selection"
android:layout_below="#id/action_search_bar" >
</ListView>
<TextView
android:id="#+id/action_preview_pane"
android:layout_width="230dp"
android:layout_height="match_parent"
android:layout_alignBottom="#id/actions_list"
android:layout_alignTop="#id/actions_list"
android:layout_toRightOf="#id/actions_list"
android:gravity="center_vertical|center_horizontal"
android:text="kk" />
<Button
android:id="#+id/cancel_action_selection"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:text="Cancel" />
<Button
android:id="#+id/define_new_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/cancel_action_selection"
android:text="NEW" />
<Button
android:id="#+id/select_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/define_new_action"
android:text="OK" />
</RelativeLayout>
Here is what I'm trying to achieve:
The problem is, if I try to set the ListView to be above the cancel button (via android:layout_above), it will say that it can't find the id for the cancel button.
Now, what I have noticed is that if I try and specify any ids for layouts BEFORE they are created with #+id, then I will get that strange error. What I mean by this is the following:
In the XML, apparently IDs have to be declared in order. Strange, no?
I would have to declare the cancel button's id first with #+id way before I define the ListView and set its layout_above attribute.
If I try to do what I have done here, it will say that it cannot find the id for the cancel button.
I have tried cleaning the project, ending adb.exe, refreshing, etc. and all it does is corrupt my project even more. R is not even generated afterwards. I don't want to have to go in a loop problem after problem because Eclipse can't handle things like this properly.
Does anyone have a solution for this? Or a better IDE?
http://developer.android.com/guide/topics/ui/layout/relative.html
RelativeLayout lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on.
So you are placing listview relative to the button cancel. So you need to define button with a id. Position the listview relative to the button.
http://developer.android.com/guide/topics/ui/layout/linear.html
There is an example in the links posted both for linearlayout and relative layout have a look at it.
Edit:
If you have errors in your resource files R.java will not be generated. So make sure you do not have errors in your resource files and then clean and build the project.
To clarify the confusion. Note android:layout_above="#+id/button1"
<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=".OtherScreenActivity1" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
android:text="Button" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button1"
>
</ListView>
</RelativeLayout>
Same as above
<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=".OtherScreenActivity1" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button1"
android:layout_alignParentTop="true" >
</ListView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="24dp"
android:text="Button" />
</RelativeLayout>
You have this
android:layout_above="#id/cancel_action_selection"
Use
android:layout_above="#+id/cancel_action_selection"
http://developer.android.com/guide/topics/ui/declaring-layout.html.
Look at the attribute id in the above link
I would like to align two buttons on the bottom of a relative layout that is wrapped inside of a linear layout.
I am unable to get the view favorites button to be on top of the search button. There is a big space as you can see in this image:
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="#string/SearchRestaurantsCity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCity" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchCity" />
<TextView
android:text="#string/SearchRestaurantsState"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchState" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchState" />
<TextView
android:text="#string/SearchRestaurantsCategories"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCategories" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spRestaurantSearchCategories" />
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<Button
android:text="#string/btnViewFavoriteRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnViewFavoriteRestaurants"
style="#style/ButtonText"
android:padding="5dp"
android:layout_below="btnSearchRestaurants" />
<Button
android:text="#string/btnSearchRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnSearchRestaurants"
style="#style/ButtonText"
android:layout_alignParentBottom="true"
android:padding="5dp" />
</RelativeLayout>
There are 2 things wrong with the XML.
For starters, you can't refer to the button btnSearchRestaurants before it's defined.
Secondly, you've defined btnSearchRestaurants to align-parent-bottom, and then tried to define that btnViewFavoriteRestaurants would be below that button. It should be above it (as per your description).
If you're trying to put the first button I can see inside RelativeLayout, I'd try to change the following line:
android:layout_below="btnSearchRestaurants" />
for this one:
android:layout_above="#+id/btnSearchRestaurants" />
Part of the space is reserved for all the elements of the layout I can see inside the LinearLayout,and the + is because the button btnSearchRestaurants is below so it is not created yet
I think the problem is at
android:layout_below="btnSearchRestaurants"
It should be
android:layout_below="#id/btnSearchRestaurants"
In your xml code I think you should correct this line
android:layout_below="btnSearchRestaurants"
as you want it to be above the Search Restaurants button it should be
android:layout_above="#id/btnSearchRestaurants"
I changed below to above for obvious reasons (you want it above the other button not below it) and added #id/ because you will be searching for the button id.
I am implementing listview with 2 textviews , and for reference used Basic Layout and Formatting
Instead of stock names which are short i am using long text, so when i use a long text, it overlaps with the second .
So how to get it right, so that the 2 textviews don't overlap each other.
You can used following code to solve your problem:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="#+id/ticker_symbol"
android:text="sdasd sadas"
android:layout_weight=".5"/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="#+id/ticker_price"
android:text="dfsd"
android:layout_weight=".5"
android:gravity="right" />
</LinearLayout>
Output:
To avoid overlapping, you could set the second textview to align to right (android:layout_toRightOf).
For example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/ticker_symbol"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/ticker_price"
android:layout_toRightOf="#id/ticker_symbol"
android:layout_alignParentRight="true" />
</RelativeLayout>
I guess you mean due to long length of text it goes to next line or on next TextView
So i suggest you to use textView property android:ellipsized="end" and also use android:single_line="true" instead this you can directly specify the maxline=1
I'm not sure with names spelled correctly so check while typing
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/ticker_symbol"
android:ellipsezed="end"
android:singe_line="true"
android:layout_alignParentLeft="true" />
Hope this explanation woks for you let me know..
I have a rather simple ListView row:
<?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="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="25dp" />
</RelativeLayout>
When the text of "#+id/tournament_name"is long - it overlaps with the one from "#+id/tournament_winner" and I don't understand why.
I tried using android:singleLine="false"to no avail. I also tried using android:inputType="textMultiLine"as the docu says android:singleLine="false" is deprecated but then I get the warning: Attribute android:inputType should not be used with <TextView>: Change element type to
<EditText> ? so no good here as well.
I also tried using android:ellipsize="end" but this doesn't work. I assume it is because the text in the left TextView ("#+id/tournament_name") is NOT long enough to fill up the full width of the ListView (which code is not sowing here).
I was sure that if I use android:layout_width="wrap_content"the two TextView fields shouldn't overlap.
Here is an example (see the second line):
Any further ideas how this could be fixed?
android:layout_toLeftOf="#id/tournament_winner" in First TextView.
Also set android:maxLines="1" and Fix width for tournament winner because when it gets long tournament name cant see...
row.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="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/tournament_winner"
android:maxLines="1"
android:text="NAMEEEEEEEEEEEEEEEEEEEEEEEEEEE"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="WINER"
android:textSize="25dp" />
</RelativeLayout>
Thank you very much for your answer - sorry it took me some time to respond. I ended up using your android:layout_toLeftOf="#+id/tournament_winner" but left the single line and the margin to the left unused, as the result seemed perfect to me (hope this is also the case for other devices).
One thing though - in the first text view (tournament_name) I had to use android:layout_toLeftOf="#+id/tournament_winner"and not android:layout_toLeftOf="#id/tournament_winner" - pay attention to the added +. For some reason I get an error using android:layout_toLeftOf="#id/tournament_winner": Error: No resource found that matches the given name... so it seems that it is possible and NEEDED to define the resource in the time of calling it because the system doesn't know it before it was defined.
<?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="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tournament_winner"
android:layout_alignParentLeft="true"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="25dp" />
</RelativeLayout>
You can use single text view in place of two and simply display both strings in one text view !!