Hi Everyone iam new to android and in my project requirement i need to create two LinearLayouts in same Position and they are animated later in the Java Code,For Testing Purpose initially i inserted image views on those layouts got succesfully after that i removed image views and Inserted EditTexts on the same layout but strange previous image is showing on one linear layout after executing which is not shown in preview
I tested all the options like cleaning the project ,uninstalling from device and reinstaling iam getting the same problem
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate Now"/>
<LinearLayout
android:id="#+id/image_list_fragment"
android:layout_width="250dip"
android:layout_below="#+id/button1"
android:layout_height="200dip"
android:background="#FF00FF"
android:layout_centerInParent="true"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Please Enter some text here"
android:singleLine="false"
/>
</LinearLayout>
<LinearLayout
android:layout_width="200dip"
android:layout_height="300dip"
android:orientation="vertical"
android:layout_below="#+id/button1"
android:visibility="visible"
android:background="#32FFFF"
android:layout_centerInParent="true"
android:id="#+id/image_details_fragment"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Please Enter some text here"
android:singleLine="true"
/>
</LinearLayout>
</RelativeLayout>
Here is the output the preview in Eclipse and output in Emulator After running
Please check your backend java file(activity class) once or paste it here. You might be setting an imageview with that background somewhere at runtime.
Related
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 trying to create a chat bubble with some text.For this I am create Three Layoutouts,Inside of main Linear Layout I am using FramLayout,I am setting a 9-patch background To this Framlayout.Inside of Framlayout I am adding one more RelativeLayout where I am placing my three textViews and one imageView.but type long text it goes outside of FramLayout border.I don't know what I am doing wrong or what I am missing.When I am using small text it remain fit but with big text it goes out from even Background Border of FramLayout.In attachment I am showing my bubble and yahoo IM bubble.I am trying to create same like yahoo but with some different style.Please give me your suggestion.I try a lot with different ways but not get success.Thanks in advance . .
Here I am placing my Layoutfile
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linearListLayout1">
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bubbleblue" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="100dp">
<TextView
android:id="#+id/chattitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"/>
<TextView android:id="#+id/chatdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"/>
<TextView android:id="#+id/chatText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/chatstatus"
android:layout_below="#+id/chattitle"
android:layout_toLeftOf="#+id/chatstatus"
android:text="TextView" />
<ImageView
android:id="#+id/chatstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/add_picture"
android:layout_alignParentRight="true"
android:layout_below="#+id/chatdate"
android:minHeight="2dip"
android:maxWidth="2sp"
android:maxHeight="2sp"
android:layout_marginRight="2dp"/>
</RelativeLayout>
</FrameLayout>
When creating your .9patch image, you also must specify a content area, which you define with the left, and bottom pixels. Check out this.
Use
and
for background of your root layout item.
right click on images and select Save target as.
Hello I am trying to get text to display like it does in terminal or cmd. And by that I mean a window of text that with each input makes a new line and then displays the bottom line of the TextView, and there would be a set amount of lines always on the screen.
It sounded easy to do, but now that I started I'm not sure how to do it.
I tried putting a TextView in a ScrollView like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >
<ScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView android:id="#+id/tv1"
android:layout_width="wrap_content"
android:minLines="11"
android:maxLines="11"
android:layout_height="wrap_content"/>
</ScrollView>
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="buttonclick"
android:text="Button" />
</LinearLayout>
and then
sss=et1.getText().toString();
tv1.append("\n"+sss);
to add new lines
This all works but I really have no idea how to make the TextView go to the bottom, right now it just cuts off when I hit the max number of lines.
I definitely don't expect anyone to write my program for me. I am here to learn
Thanks for your time!
Call fullScroll(View.FOCUS_DOWN) on the ScrollView after appending the text.
I have a problem with designing an UI Android activity. There are two blocks of misplaced graphics on the left and right of the activity - they are two lines just bellow the titlebar with 1px height and about 5-10px width. They cause buttons to break at their left and right parts. I cannot figure out what the problem is. I am using Eclipse with Android SDK 0.9.9. The lines appear not only with the emulator but in a HTC Wildfire (Android 2.1). These lines are also visible in a newly created Android project (HelloWorld).
Sorry, but I was not allowed to post images, being too new here :)
Link to the Broken widgets - note the button's left and right sides
XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:fitsSystemWindows="true">
<TextView android:layout_height="wrap_content" android:text="This text view should act as header " android:id="#+id/expenseHeaderTxt" android:layout_width="fill_parent" android:paddingLeft="5px" android:paddingRight="5px"/>
<ScrollView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginBottom="50dip" android:id="#+id/expenseScrollView">
<RelativeLayout android:id="#+id/RelativeLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scrollbars="none" android:paddingLeft="5px" android:paddingRight="5px">
<EditText android:layout_height="wrap_content" android:id="#+id/expenseAmountEdit" android:hint="#string/ExpenseAmountHint" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:selectAllOnFocus="true" android:digits="0123456789" android:inputType="number|numberDecimal" android:maxLines="1"></EditText>
<EditText android:layout_height="wrap_content" android:id="#+id/expenseTypeEdit" android:layout_width="fill_parent" android:layout_toLeftOf="#+id/expenseAmountEdit" android:hint="#string/ExpenseSpendTypeHint" android:inputType="text|textCapSentences" android:maxLines="1"></EditText>
<ToggleButton android:layout_below="#id/expenseTypeEdit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/expenseTypeSignToggle" android:textOn="#string/ExpenseTypeSignPlusToggle" android:textOff="#string/ExpenseTypeSignMinusToggle"></ToggleButton>
<EditText android:layout_below="#id/expenseTypeSignToggle" android:layout_height="wrap_content" android:id="#+id/expenseNoteEdit" android:layout_width="fill_parent" android:hint="#string/ExpenseNoteHint"></EditText>
</RelativeLayout>
</ScrollView>
<RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent" android:paddingLeft="5px" android:paddingRight="5px">
<Button android:id="#+id/expenseAddBtn" android:layout_width="fill_parent" android:text="A button that should always be at the bottom" android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
Funny, I also had the ListView dividers disappearing when scrolling and during the hunt I found the code here:
Disappearing dividers in Spinner drop-down list
It not only fixed the issue with the disappearing separators but also fixed the broken layout.