How to Add Layout on the Top of another Layout - java

How to bring layout or view on the top of another view or layout
enter image description hereas shown in the picture

What you want exactly?
See you can do it in two way:
Take a android.support.v7.widget.Toolbar inside it take a Relative Layout then take a Textview and RelativeLayout with an ImageView inside it. Align the RelativeLayout with ImageView on the right side and the TextView to the left of it.
Take a android.support.v7.widget.Toolbar and below it take a RelativeLayout with ImageView and align it to Right and Top

Related

MapView extends when BottomNavigationView is gone

So every time is set my BottomNavigationView on gone the MapView gets bigger in size and when I set it back to visible it shrinks back to its original size. Is there a way to make the MapView have the size of the full screen even when the BottomNavigationView is visible ? Here is a GIF
Is there a way to make the MapView have the size of the full screen even when the BottomNavigationView is visible ?
Yes there is.
Use something like RelativeLayout as the root layout and set the width and height of the MapView to match_parent.
Also add the BottomNavigationView as the child of root layout with attribute android:layout_alignParentBottom="true".
Most importantly, do not use LinearLayout as parent and do not place the MapView and BottomNavigationView relative to each other.

How to decrease the height of a linearLayout with initial height as fill_parent

What I am trying to achieve is to implement a typical texting screen, where I have a LinearLayout initially occupying the whole screen by setting the height to be fill_parent, except a RelativeLayout containing an EditText at the bottom of the screen using android:layout_alignParentBottom.
Now, I need to display an extra RelativeLayout at the bottom of the small RelativeLayout, which should reduce the height of the LinearLayout, and push the original RelativeLayout up.
Please advise what is the best way to achieve the above scenario. Thank you.
I find easier the use of RelativeLayout for cases like this.
You can define a RelativeLayout as a container of all of them and
place the others inside it.
Set your LinearLayout height to "match_parent"
Place the EditText below the LinearLayout; and the RelativeLayout,
below the EditText; using android:layout_below
Good luck friend!

Android: Prepend LinearLayout programmatically

I created a layout in my application that includes the followings:
main_layout (FrameLayout, fills whole screen)
-> includes: main_interface (LinearLayout, height/width fills parent)
Now I want to add another LinearLayout in the main_layout BEFORE the main_interface.
I tried this:
LinearLayout bar = new LinearLayout(this);
bar.setGravity(Gravity.TOP);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
bar.setLayoutParams(params);
main_layout.addView(bar);
but this just overlaps my main_interface.
Any Help?
If you want to add a View to specific position in a ViewGroup, you can use addView(view, position). In this case, assuming main_interface is the first View, you can call main_layout.addView(bar, 0).
However, you need to fix your layout first. If you use FrameLayout as your main_layout and set main_interface height and width to match_parent, then they will surely overlap. Try making your main_layout a LinearLayout with android:orientation="vertical" if you want vertically stacked Views.
If you could post your actual XML layout, I could help you modify and test it.

Dynamically put textview above another view in relativelayout android

Hi by doing java code i have done successfully add textview in relative layout like BOTTOM|RIGHT
but i want to put textview above bottom bar layout
here is the image
here u can see that there is a textview which has white background image and its back it has black bottom baar i want to put textview above's bottom bar
Below is my java code
LinearLayout bottomBar = (LinearLayout)findViewById(R.id.bottomBar);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(150, 70);
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params1.addRule(RelativeLayout.ABOVE, bottomBar.getId());
butAddText.setLayoutParams(params1);
By doing this i have added bottom left but last two lines is not working i can not add textview above the bottom bar..
can any body help me please
I suspect the problem is that you've set 2 conflicting rules.
Try to remove the next line:
params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
The reason: you've tried to set the view to the bottom of its parent, and also above another view.
Simplest way may be simulate nested layouts:
<LinearLayout ...>
<TextView/>
<RelativeLayout/>
</LinearLayout>
But it may decrease performance.
Edit:
First inflate your LinearLayout(it's orientation is vertically) then add your TextView and your bottom bar.Also if you want to align TextView right,you can use a RealtiveLayout instead of outer LinearLayout.

Setting Layout Parameters Programmatically

I'm trying to add a scroll view inside another scroll view.
It should look like is this:
scroll view
linear layout
myprogramaticscroll view
myprogramticlinear layout
myprogramticbutton
end button
end layout
end scroll
end linear
end scroll
I'm trying to add scroll views inside of that. It goes in there, but I need to know how to set parameters correctly so I can see the whole button I have inside of my scroll view. I only see part of it, and I need to set the programatic linear layout and scroll view's width height and id. How do I do this? This is what I have so far:
//the layout I'm putting my scrollview/linearlayout/button in
LinearLayout l = (LinearLayout) findViewById(R.id.linearLayoutFavorites);
ScrollView scroll = new ScrollView(this);
LinearLayout nl = new LinearLayout(this);
ImageButton yourButton = new ImageButton(this);
nl.addView(yourButton);
scroll.addView(nl);
l.addView(scroll);
You CAN'T put a scroll view inside another scroll view, that behavior would be odd, and Android would not know how to handle your scroll on the views.
For setting layout parameters, take a look at ViewGroup.LayoutParams, there're actually quite a few subclasses of ViewGroup.LayoutParams, which are for setting layout parameters for different kinds of layouts.
You can use a Scrollview in an another Scrollview. But this is not suggestible. It will be an issue to both the user and android OS. It will leads to Memory issues and also touch issues while scrolling the views. If you are expecting the Two scrolls (Horizontal and Vertical) at a time, then it is preferble to go for TwoDSCrollView
If you want to set the Layoutparams you should look at ViewGroup.LayoutParams.
If you want to set width and height then no need to set the Layoutparams. You can get the existing params by using getLayoutParams() for the view and set width and height to that params.
If you want to place vertical in vertical scroll or horizontal in horizontal scrollview the you should set the height of the internal scrollview height to the actual height of the total childs.

Categories