overlapping layouts one above the other - android

I have an edit text whose height I am setting as wrap_content.
I have some layout below the edit text.
when ever i write data in it and press enter to go to new line because of wrap content the size of edit text increases and its height increases downwards.Also the layout below is pushed down.
I want the layout below not to be pushed down but the edit text should overlap the layout below. Can this be done?

If you want overlapping layouts you need to use something like a RelativeLayout, if you were to only use a LinearLayout all the layouts will be placed in order.
If you use a Relative Layout you could define that all the TextViews start in the top left but the second one could have a margin so it is offset from the top. Then when your top textbox expands it would overlap the other (assuming the first TextView is drawn afterward , to do this list it in the XML after the other)

Related

How can I center two TextViews vertically within a Layout

I have a RelativeLayout (that I am not married to) and two TextViews. I would like the bottom of the first TextView to line up with the center of it's parent, and the top of the second TextView to line up with the center of it's parent.
I put a green line in the picture above at the (vertical) center of the parent. The TextViews are currently in exactly the right spot, but I did this as I will describe below with margin's and aligning them to the parent and knowing the parent's size.
For various reasons I can't use just one TextView and center it. Also I don't know the height of the parent, so I can't align each to the top/bottom of the parent and margin them down/up to center them.
I also tried having another View that takes up half the height and be invisible, but layout_height doesn't take percents (or at least it gave me errors).
Any ideas how I can accomplish this?
Should I just put the two TextViews inside another layout and have that center itself?
Create a 0-height view that is centered in its parent and serves as an anchor. (Use the attribute android:layout_centerVertical="true" for this.) Position one text view above the anchor and the other below the anchor.
I've solved this problem before by using a vertical LinearLayout with the two TextViews inside it.
ps.: the Android Design Guidelines http://developer.android.com/design/patterns/pure-android.html specific points out to Don't use right-pointing carets on line items. It might not be a line item that you're doing, but in case it is, just to point it out.

How to shift parent layout to right without changing inner components layout?

In my application I want to have sliding menu on the left side just like facebook.
In my previous question I had raised concern regarding the same and thanks to this answer that I could found a way to slide my layout to right using this library. But, I found that, the library does not actually slides the layout, instead it just takes the screenshot and slides the image towards right as the components on the layout are not clickable. And I need those components to be clickable. So, I tried a new way of achieving this by putting the slideout menu on the left by keeping its default visibility to View.GONE and make it visible on click on left top corner "Show/hide Menu" button as shown in figure below.
Layout before:
Now when I click "Show/Hide Menu" button, the layout is something like-
Layout after:
As you can see, the layout on the right shrinks and so the button "Some other view" changes its width even if I've set the android:minWidth attribute to those two buttons on the right as well as its parent RelativeLayout.
So my question is, is there any way to shift the layout towards right without the inner components changing their width/layout? So in whatever area is available for my view, it will be filled by whatever portion of the content that can be filled in in that area.
This problem can be solved like this:
create framelayout with inside: first left menu with 3 buttons and second layout that contains other two buttons (show/hide and other view). This way, the second layout is in front of menu (since it is fill_parent).
in onClick of show/hide button perform translate animation: assuming that your menu is 200px wide, move the second layout by 200 to the right.
in onAnimationEnd, set margins to the second layout like this: secondLayoutLayoutParams.setMargins(200, 0, -200, 0);
Closing menu is similar: move the second layout to the left by 200 and set all margins to 0.
By setting margins you will avoid button shrinking.
Hope it helps
#Rajkiran - I have a root layout, that contains my left & right layouts.
My right layout has layout_height set to 'match_parent' & layout_widht is also set to 'match_parent'
Now when my left sliding panel appears on button click, I reset the width & height of my right layout programmatically to match the width & height of the root layout.
This perfectly shifts the right layout towards right without the inner components wrapping up.
To change height & width programatically I used this -
rootLayoutParams = new LayoutParams(rootLayout.getWidth(), rootLayout.getHeight());
rightLayout.setLayoutParams(rootLayoutParams);
Hope it helps you as well.

Ensuring 2 linearlayouts that replace each other have the same size

I have a top section for the app which is mainly logo and stuff, and roughly the bottom half is supposed to be buttons.. In the outer container, i have a layout for the logo, and imageView to create a seperator line between the top and bottom and the bottom layout..
The issue is bottom layout has 2 linearlayouts (one of which is hidden initially) first one is just a spinner and the second one is 2 buttons..
I have achieved the "roughly 1/3 of space) by using layout_weights in the top and bottom linear layout (2 and 1 respectively) but when I hide the spinner and show the 2 buttons in the bottom layout in the code, the seperator line is pushed up.. I want it to stay in the same place (like be where it would be after the 2 buttons show up from the get-go so that it doesn't have to move)
I could probably just add some margin to the original one to match it but i feel like that will cause issues in the future on different devices.
How can I accomplish this feat?
I think you might be neglecting to set android:layout_height="0dp" on the LinearLayouts that you set android:layout_weight="1" on. If you do this it should fill the space like you want, and you can do layoutView.setVisibility(View.GONE) and layoutView.setVisibility(View.VISIBLE) to toggle the views.

UI - How to display GridView and Linear layout togather

I want to display GridView (with text and image) and group of text box below grid view.
Problem is my gridview do not have fixed entries. It is varying between 1 & 10. I want to resize it as per count of items in grid view. How can i do that? Where can i get height of gridview in JAVA code?
Also, i want to display my group of text boxes ALWAYS at bottom of activity. How can i do that?
Thanks,
JC
I want to resize it as per count of items in grid view.
I really don't recommend that.
Also, i want to display my group of text boxes ALWAYS at bottom of activity. How can i do that?
Step #1: Put the GridView and the LinearLayout inside a RelativeLayout
Step #2: Anchor the LinearLayout to the bottom via android:layout_alignParentBottom="true"
Step #3: Anchor the GridView to the top (android:layout_alignParentTop="true") and to the top of the LinearLayout (android:layout_above="...")
This will cause your GridView to expand to fill the space in the RelativeLayout except that which is taken up by the LinearLayout at the bottom. You can size and position the RelativeLayout yourself as you see fit (e.g., set width and height to fill_parent to have it fill the screen).

Linear Layout Issue at Runtime

I am trying to build a layout dynamically which display some text and image for the most part, but has a series of buttons placed next to each other in the bottom.
I have a linear layout that carries the text, another linear layout that carries the image. And yet another linear layout that carries the buttons that get created in a for loop. I have a main layout aligned vertical that adds the text, image and buttons layout, in that order. To finally generate something like this:
Text ....
Image ...
Button1 Button2 Button3....
The problem is the number of buttons get decided at runtime, so if there are more than 4 buttons, the 5th button gets displayed really tiny. Also, when I tilt the phone, I get only the text and image showing, but no buttons coz the image covers the entire screen.
Layoutting seems to be pretty complicated to me, any help is appreciated!
Thanks
George
You do not need to wrap single views in a linear layout, so add the text and image directly to the root linear layout. You might consider using a relative layout instead of linear for the root.
Using FILL_PARENT and WRAP_CONTENT for the LayoutParams width or height can give some useful results. For example, using FILL_PARENT for the image height might scale it down to leave room for the buttons.
Be careful with LayoutParams because there are lots of them and only the one that matches the ViewGroup class should be used.
One option would be to implement an onLayout method of your own in a custom ViewGroup. You will be passed the dimensions you have to work with and be able to position all the views as you see fit.

Categories

Resources