How do I position a two views, on top of each other, at certain coordinates, in Android?
Add just layout_gravity attribute in com.google.ads.AdView view as follow
android:layout_gravity="left"
CSS: How to position two elements on top of each other, without specifying a height?
First of all, you really should be including the position on absolutely positioned elements or you will come across odd and confusing behavior; you probably want to add top: 0; left: 0
to the CSS for both of your absolutely positioned elements. You'll also want to have position: relative
on .container_row
if you want the absolutely positioned elements to be positioned with respect to their parent rather than the document's body:
If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 'position' of 'absolute', 'relative' or 'fixed' ...
Your problem is that position: absolute
removes elements from the normal flow:
It is removed from the normal flow entirely (it has no impact on later siblings). An absolutely positioned box establishes a new containing block for normal flow children and absolutely (but not fixed) positioned descendants. However, the contents of an absolutely positioned element do not flow around any other boxes.
This means that absolutely positioned elements have no effect whatsoever on their parent element's size and your first <div class="container_row">
will have a height of zero.
So you can't do what you're trying to do with absolutely positioned elements unless you know how tall they're going to be (or, equivalently, you can specify their height). If you can specify the heights then you can put the same heights on the .container_row
and everything will line up; you could also put a margin-top
on the second .container_row
to leave room for the absolutely positioned elements. For example:
http://jsfiddle.net/ambiguous/zVBDc/
How to position a view on top of another view in RelativeLayout?
Put your LinearLayout
after TextView
like this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" <!-- this because the textview is the topmost view on the screen so I tried to use this -->
android:text="my text"
android:textSize="10pt"
android:id="@+id/text1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text1"
android:orientation="vertical"
android:id="@+id/linear_layout">
<!-- some other views -->
</LinearLayout>
How can I stack two views on top of each other?
I set the size
You should not set the size.
If you are using components on panels, then each layout manager will determine the preferred size.
If you are doing custom painting then your component should implement the getPreferredSize()
method so layout managers can do their job.
when I use BoxLayout I am not able to place two components on the left side
JPanel subPanel = new JPanel(new BoxLayout(this, BoxLayout.Y_AXIS));
subPanel.add(gameView);
subPanel.add(timeView);
You are setting the wrong panel to use the BoxLayout.
The code should be:
//JPanel subPanel = new JPanel(new BoxLayout(this, BoxLayout.Y_AXIS));
JPanel subPanel = new JPanel();
subPanel.setLayout(new BoxLayout(subPanel, BoxLayout.Y_AXIS));
Or an easier way is to sue the Box
class:
Box subpanel = Box.createVerticalBox();
Place View on top of other View in React Native
Ok so I found the problem xD
Apparently the elevation={3}
messes it up. Everything works if I simply remove this prop from the row Views.
How To Position Views Relative To Their Top Left Corner In SwiftUI
@Asperi 's answer will solve the problem. But, I think we should use Spacer()
rather than Color.clear
and ZStack
.
Spacer
is specifically designed for these scenarios and makes the code easier to understand.
struct HomeView: View {
var body: some View {
HStack {
VStack(alignment: .leading) {
Text("Top Text")
.font(.system(size: 20))
.fontWeight(.medium)
Text("Bottom Text")
.font(.system(size: 12))
.fontWeight(.regular)
Spacer()
}
Spacer()
}
}
}
SwiftUI layout system is different from UIKit.
It asks each child view to calculate its own size based on the bounds of its parent view. Next, asks each parent to position its children within its own bounds.
https://www.hackingwithswift.com/books/ios-swiftui/how-layout-works-in-swiftui
Position two image view on top of another
One option must be using a FrameLayout
Android Layout Tricks #3: Optimize by merging
or using a RelativeLayout
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_bottom"/>
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_top" android:layout_alignParentBottom="true" android:layout_alignParentRight="true"/>
</RelativeLayout>
Update: I found this @ Stackoverflow:
how to place an image over another one on android app?
Related Topics
How to Convert Uicolor Value to a Named Color String
Unnotificationattachment with Uiimage or Remote Url
Change the Root View of Uihostingcontroller in Swiftui
How to Set Http Header Fields in Objective-C
Responding to Ram Availability in iOS
Swift JSON Error:Could Not Cast Value of Type '_Nsdictionarym' to 'Nsarray'
How Get the List of Errors Thrown by a Function
How to Use Local-Only Project via Cocoapods
What Are the Differences Between a Uiview and a Calayer
How to Get the Rootviewcontroller from a Pushed Controller
Memory Leak When Using Nsurlsession.Downloadtaskwithurl
How to Send Email Using Mfmailcomposeviewcontroller in Simulator
How to Change Status Bar Style - iOS 12
Exception Type: Exc_Crash (Sigabrt)
Get Error Code -11843 While Exporting Mp3 File in Ipod Library Since iOS 5.1
Tap Gesture on Animating Uiview Not Working
Swift - Checking Unmanaged Address Book Single Value Property for Nil