I am attempting to draw the medal overlaying the corner of the score screen shown here
There is an transparent layout holding the buttons and a RelativeLayout (black edge box), which holds the interior box (grey box) that contains the rest of the data. I tried adding the medal to the top left corner of the interior RelativeLayout and giving it negative margins, but that just cuts it off at the edge of the view. Adding it to the transparent layout puts it behind the corner.
How can I force the medal to overlay that corner? I'd prefer to do it in xml if possible, but any suggestions are welcome.
You can also achieve this by setting the android:clipChildren="false" and android:clipToPadding="false" attributes on the parent view (and if that doesn't work, set it on all the ancestor view groups as well, eventually it will work).
In the xml layout, an element that define after will overlay the element that define before.
So, you could change layout to something like this:
<LinearLayout>
<LinearLayout> <!--grey box --> </LinearLayout>
<ImageView src="medal" android:layout_marginLeft="-250dip"/>
<!-- change the amount of marginLeft to your desire -->
</LinearLayout>
merge them ...
http://developer.android.com/resources/articles/layout-tricks-merge.html would help
Related
This is the layout I want to design:
As you can see from the image, I want the linear layout to be constrained to both Item A and Item B and I want it aligned to left. I couldn't find any way to implement this inside a Constraint Layout. When I use this:
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="wrap_content"
android:layout_height="#dimen/ui_size_xs">
linear layout moves to the middle.
When I use this:
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="0dp"
android:layout_height="#dimen/ui_size_xs">
the linear layout occupies the whole area between Items A and B.
I want the linear layout to be wrap-content but should also align to the left like in the image. The only solution I could find is to create a new layout as parent of this linear layout and give 0dp to new parent linear layout and wrap-conent to this layout child layout. I don't want to do that. Is there any way to achieve this without creating any extra layout?
As mentioned in offical docs,
The default when encountering such opposite constraints is to center the widget; but you can tweak the positioning to favor one side over another using the bias attributes:
layout_constraintHorizontal_bias
layout_constraintVertical_bias
Try the following and see if it works
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="wrap_content"
android:layout_height="#dimen/ui_size_xs"
app:layout_constraintHorizontal_bias="0.3"
app:layout_constraintLeft_toRightOf="item1id"
app:layout_constraintRight_toLeft="item2id">
// try different horizontal bias values to meet your need
This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX). These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections
add properties to your view like app:layout_constraintStart_toStartOf="parent" and app:layout_constraintTop_toTopOf="parent" and then give margin to set where ever you want.
and you can find all property of constraint layout here ConstraintLayout
You can set the vertical constraint for your view like this
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
Or you can use the UI Editor from android studio, select the dots on the top and bottom of the view and drag them to the parent, this will set the vertical constraints, you can them edit them directly from xml or UI editor.
UiEditor Screenshot
I have a tabstrip Layout that has been taken from the google github (latest version) and I am having trouble with the tabstrip as there is a gap between the indicator line and the bottom of the tabstrip. To make it more clear the layout consists of a viewPager(white) which goes below the Tabstrip(green), they are both different colors. the text Views in the Tabstrip are evenly distributed along the x axis but not on the Y axis hence there is a gap of green below the Tabstrip. I want to remove this gap but have the same height and when I do reduce the height the text is pushed up.
Code xml layout (in Linear Layout)
<!-- The pager that allows us to swipe between fragments -->
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:background="#android:color/white" />
I also want to try different colours for the indicator and if not remove it and finally I want to change the colour of the text.
Any help is appreciated. Thanks in advance.
the black part is a video View I left that out of the code
I wanna put image in top of View and a listview bottom of it.
what's best and correct way?
LinearLayout?RelativeLayout?
and with which attribute?
layout_gravity="top"?
layout_alignParentTop="true"?
please give me a snipped code and a brief description about:
what's different between layout_gravity="top" and android:layout_alignParentTop="true"?
I wanna put image in top of View and a listview bottom of it. what's
best and correct way?
If you want to place a ListView below an ImageView positioned at the top of the current view then you could use both layouts, it isn't any real difference.
The layour_gravityis used to place the children relative within its parent bounds(the Relativelayout doesn't have this attribute). For example you could use a LinearLayout with orientation vertical which will stack your two children one on top of the other like you want. Also layout_gravity="top" is ignored for a vertical orientated LinearLayout as it doesn't make sense, so you could remove it from the layout completely:
<LinearLayout android:orientation="vertical">
<!-- the layout_gravity is useless int this case and could be removed-->
<ImageView android:layout_gravity="top"/>
<ListView />
</LinearLayout>
layout_alignParentTop is a placement rule for children of RelativeLayout(only for this type of layout!) which tells them to position aligning the top of the children with the top of the parent RelativeLayout. In this case, to stack the children you would do:
<RelativeLayout>
<!-- you could remove the layout_alignParentTop attribute because by default the Relativelayout will position it's children there -->
<ImageView android:id="#+id/imageId" android:layout_alingParentTop="true" />
<!-- Position this child below the other -->
<ListView android:layout_below="#id/imageId"/>
</RelativeLayout>
Is is possible to put fixed buttons (with image) on top of an android map.
I want to add buttons on top of the android map then when the user click on it, it performs something on the map.
Similar to the zoom control, but always visible.
Put the map and the button in a relative layout. Something like:
<RelativeLayout>
<MapView>
...
</MapView>
<Button>
..make its align parent top property true here
</Button>
</RelativeLayout>
This should put the botton on top of the map and aligned to the top of the screen. And if you want to have a button with an image use ImageButton insead.
You're referring to depth or z-indexing when you're saying "on top of". Use FrameLayout and set MapView first then followed by Button.
<FrameLayout>
<MapView />
<Button .../>
</FrameLayout>
Edit I mentioned gravity which was wrong.
Related question: Placing/Overlapping(z-index) a view above another view in android