Android :: How To Set Button X Y Position In Layout?
Oct 5, 2009
i am trying to display a linear layout , say at setpadding (10,10,0,0); now i need to put some buttons at particular xy position in layout.button position doesn't seem to work in that way. can anybody suggest how can i set button position in layout?
My customRelativeLayout at the bottom of the XML has a XML layout too:
What I want to do: I want to be able to change the position of my CustomRelativeLayout. It should be follow my touch. Its smaller than the SurfaceView and should "slide" above following my touch...
There are two problems:
The onTouchListener bind to mLinearLayout (in CustomRelativeLayout) is only triggered once and only for ACTION_DOWN. I see the log output only once The note never changes the position, it is never redrawn with the changed matrix... I see the output stated in onDraw never after the touch happened.
First might be because the SurfaceView also handles touch events. But I thought if the CustomRelativeLayout handles it first, it should work.
Thanks to Xil3 I was able to remove the wall I was run into...
Here is my solution:
My note xml:
And here is my constructor:
I also found a bug/feature/issue, which is absolutely new for me: When I remove the background in my note root element (which is currently transparent) the note is only visible within the 200dp width/height I have set in the inner LinearLayout. So its not fill_parent, its wrap_content even as I set it to fill_parent. So layout_width and layout_height only use the given fill_parent when a background is set...
RelativeLayout is more flexible, and can do what AbsoluteLayout can do and more. http://developer.android.com/reference/android/widget/RelativeLayout.... To place views on top of one another you can also use FrameLayout, positioning these frame layouts in their parent layout: http://developer.android.com/reference/android/widget/FrameLayout.html
18.08.2010 19:11, ericmahlon пишет: > I have an image that will have 5 different areas that will be "clickable." Each clickable area will be invisible and play a different sound. I was told not to use an absolute layout, and use a linear layout instead. However, I am now having an issue with placing the buttons over the picture. The linear layout does not allow me to position them correctly where they need to go. How do I properly position a button so that it is over a certain part of the image?
The content of the TextView might change on runtime. (discussed on a different issue here: http://stackoverflow.com/questions/3683727/layout-with-dynamic-position )
I can position the layout by drag&drop. If the size of the layout doesn't change, the position stays, but as soon as the size of the layout changes (because more text inside the TextView) the position is reseted. I use the layout(left, top, right, bottom) to position the layout.
Now I don't know where I should add my layout() call to make sure it stays at the right position...
Context Menu seems quite handy as long as we are using an AdapterView as we can easily get selected item position in onContextItemSelected from AdapterContextMenuInfo.position Any idea how we can achieve something similar in a TableLayout? In my TableLayout, i have some TableRow and i would like to get the row index in the onContextItemSelected callback like i would do with a simple ListView. I guess i will have to register the contextmenu for each row? but how can tie the row index with the menu? i see no way to do it with registerForContextMenu.
I have a custom view that I had to write for a large scrollable image, as the images are larger than the size of the screen. Before, I had tried to do it by putting the image into a ScrollView but that of course didn't work. The view itself is within a RelativeLayout within the activity and at the bottom of the screen I have two buttons that are used for navigation and at the top a TextView with a caption for the activity (the main header is already being used here for instruction). In my below code, I've checked the Hierachy Viewer to confirm all the elements are loaded and in the Activity I can see the TextView, however it overlays the ZN5ScrollView area and below the image I just have a blank area of the size defined rather than my buttons. For the bottom navigation, the Hierachy Viewer is saying the absolute_y of the bottom navigation is 480. I'm wondering if anyone can help with my layout code here to get this working correctly? Bottom navigation is 50px high, ZN5ScrollView is 365px above the navigation, and the TextView takes up the rest of the area at the top
I'm trying to build an android application that features a graphical display drawn within a RelativeLayout. I want to place "+" and "-" buttons next to several of the parameters, which are drawn at various points on the canvas. The positions are free-form don't seem to conform to any of the standard XML layouts.I know how to create the buttons programmatically, but I don't know how to place them over the canvas where I need them to be. I'm assuming that this would be done in the view thread's doDraw() method, after all the graphics have been drawn, but how?
I would like to change margin of my buttons in application. Suppose I have 5 buttons like this in a linear layout, one below d other. When I focus on a button, its width should increase (which I know how to handle) and at the same time, width should increase linearly towards both left and right. i.e. If the current width of the button is 250 with x co-ordinate as 50 (that means button's left is 50 and button's right is 300), when I focus on the button I should get x co-ordinate as 75 (left = 25 and right = 325). How to change the margin/x co-ordinate of the button?
In emulator, size of edittext and button looks nice but in motorola milestones, both of them are so small. I think there are different types of screen layout. Is it possible to adjust the size automatically?
My external button is stuck down, and when I press the power button to wake my phone up it thinks that I am pressing both at the same time. So the phone goes into the Hboot screen, where I cannot choose a function. (because the volume button is stuck down position.) I have to remove the battery and wait about an hour or so then re-insert the battery and pray that it loads up. What can I do to stop this from happening? Or is there a way to control the Hboot screen other than using the volume button?
i've just returned to Android after about a year and a half and I never remember having this "issue" with my old galaxy s2x. But i am finding that whenever i am scrolling down a list, facebook, instagram, or even a webpage, and i hit the back button, it always starts me from the very TOP of the page again. I am used to just hitting back and having it remember my position halfway down or wherever i was. is this just an android thing?!
I would like to apply both an icon and text to a button. The button would have the icon centered in the button and text written at the bottom, centered. I could not get the text to center and be at the bottom using android:gravity.A side note, for a layout with 6 buttons is a Table Layout the best way to do it? There is 3 rows and 2 columns.Another side note, why does the button lose its rounded edges when I add background color?
each child is horz linear layout w/ 3 children: image view, linear layout container and then an image button if the image button is GONE - then i get click notifications when someone clicks on the list entry. if the image button is VISIBLE (even if i don't intercept onclick) - i don't get the list click event notification.
I need to add a button to the above layout problematically which is right justified? I need to do that in code instead of layout xml file (this is because i can't modify that layout xml file). Here is what I am doing: LinearLayout header = (LinearLayout) findViewById(R.id.header); Button buyButton = new Button(this); buyButton.setText(R.string.buy_ringtone); buyButton.setLayoutParams(new LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); header.addView(buyButton); But the button does not appear. Can you please tell me how can i achieve that?
Is it possible to create a button with a custom xml layout? Now I want to use this on a button. Anyone know how I can do this? I was thinking if I had Button.java file that extended Button. And then setView( R. layout. mylayout.xml); but that was to easy, and it clearly not working
I'm expanding on the hello world application. I've created a button on the main.xml to bring up a new form, screen2.xml, with a second button. I'd like this this button to toast a message. However, as soon as I try add the code to define the OnClickListener, I get a force close message.Does this mean one Activity can only access one screen/layout?
I am using a linear layout to display a pretty light initial screen. It has 1 button that is supposed to centre in the screen both horizontally and vertically. However no matter what I try to do the button will top align centre. I have included the XML below, can some one point me in the right direction? <?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">
My LinearLayout has a button and a WebView. The problem is that only the first one in layout can be clicked, the other is not. If I put WebView first into the layout, the button is not clickable. If put button in the layout first, then WebView is not clickable.Is there a setting to enable this?
I want to layout a button with Drawable image on the top of it and text below the image. I am very new to this so please use detailed instructions.I have not experimented with drawable images yet so I want to clarify before I continue.If I want to above the text (ie the text is not on the image) how do I go about doing this? I also want the text to be centered in below and (working without the drawable) there is a gravity command for center-horizontal and bottom. This made an error. Appreciate the help and remember I am a beginner to Eclipse and Java.
i' making a remote-app, so i need a varying number of buttons, grouped by tableviews and tablerows.i can create the fix ones (that must alwasy be available) at designtime via xml, making use of the layouts making all buttons fit on every resolution.but there are buttons i have to create at runtime.to make them behave the same way as the fixed ones, i need to assign the layout width, -height and -weight values.i was searching the whole documentation, but there it's alwas done in xml, no word about runtime / matching routines.
i have to use some timepickers on my layout, but i dont need the PM buton, i just want to have 24 hours sistem on the timepickers this is possible? it is bassically to call "setIs24HourView(true)" but not from the java code, from the layout
I am working on a fairly basic screen layout for my first Android application and running into some issues. My goal is to have a TextView in the top left and top right corner, a large "hello world" TextView in the exact middle of the screen, and then a button at the bottom of the screen.My issue is, to center the "hello world" TextView vertically, I need to set the layout_height="fill_parent".However, this causes the middle TextView to cover and hide the button at the bottom of the screen. Is there a better way to do this than what I am currently trying?