I cant move any elements in the layout (android studio) for some reason..
I searched alot and nothing worked with me.
All text views or buttons (all elements) stays top-left and I cant move them or even resize them...
Whats the solution for that?
And if I tried to resize the button it fills up the whole screen.
thats the code view
This is happening as you have used constraint layout in your XML file.
and the constraints as you have given in your file that makes your elements stay up at the top left.
Solution 1:
When you give start to start constraint to the parent and end to end constraint to the parent it makes your view to stick to the both side of the screen.
Even if you have given your view's height and width to wrap content it will be considered as match parent.
<androidx.constraintlayout.widget.ConstraintLayout ...>
<Button android:id="#+id/button" ...
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</>
as This will make your view to stretch to the both side of the screen and will take whole space horizontally.
all you need to do is remove the constraints mentioned below:
if you want to let your view to stick to the left side of the screen-
Remove EndtoEndof = parent constraint
if you want to let your view to stick to the right side of the screen-
Remove StarttoStartof = parent constraint
The issue with resizing the button is that you have given the constraints to the view to stick to bottom and top of the screen so it will take up whole screen vertically.
if you want to make your button to stay to the bottom
Remove toptotopof = parent
if you want to make your button to stay to the top
Remove bottomtoBottomof= parent
all you need is to understand how constraint layout works .
Look into this link it will help you understand the constraint layout from broad perspective.
I am developing an app with an activity with member reactions on a hike event. The reactions are the yellow "balloons" which are made using a LinearLayout. Each item is constructed from a XML file (listitem_deelnemerreactie.xml) which defines the layout for a reaction item. The top level of this layout file is a LinearLayout my itself.
I want some spacing between the separate elements, as well as some right margin. The most straightforward way to so this should be: setting a bottom and right margin on the top-level LinearLAyout element of the listitem_deelnemerreactie.xml layout file.
But setting the bottom margin on the LinearLayout has no effect on the vertical spacing, though the right margin does have an effect.
The only way to be able to set a vertical margin appears to be: setting is in the Java code, after attaching the inflated view to the container.
See the two images for the effect and the code.
Though setting the margins in the code is a working workaround, I still think it is strange this cannot be achieved in the XML. Why is the bottom margin attribute ignored while the right margin is not?
Any ideas?
Have you tried to set an android:padding="10dp" for example on your elements to spaced them ?
I want to add a image button on the right side of the row in my linearlayout. I tried it with padding left which works but a grey shadow is visible for the padding area. How can I achieve this with linearlayout but without the shadow. Does someone know how to achieve this?
Thanks
android:gravity="right" into your XML code should do the trick. Essentially, this will force the View to head to the right part of the view.
Hello i have used a Relativelayout in android using XML but when i see image in graphical layout there is small margin left at bottom in different screensizes.How to remove that margin.I also used a ScrollView in layout.
I think you have to set bottom margin in negative
like
android:layout_marginBottom="-10dip"
Check whether you have used padding for your layout,
Better post your layout file and/or screenshot.
How do I go about implementing a button bar with buttons of different shapes and heights? As an example (please excuse my poor drawing skills for this quick mockup):
The example bar has 3 buttons, with the middle button (3) a different shape and height than the other 2 buttons (1,2). The button bar will be a view that is included and merged into other views so as to seem to float on top of the parent view.
I was thinking of implementing buttons 1 and 2 into a layout, and then button 3 as another layout that I then merge with the first two button's layout.
like my previous comrades said, you need some kind of layout or container that can have a background (if you wish for button #3 to hoover above it) then use relative layout for mixing the two the disadvantage of this other than complexity is that youcannot relate to the other two buttons since they reside in a different layout.
More elegant solution may be to have a special background drawable that can:
have a method setCurrentHeight() that will specify the height the actual viewable section should have the rest will be filled with transparent color.
override it's own draw so just before it's drawing it will have a callback called, call back you can register yourself to.
then you can register the callback in your activity to take the current position of the #3 button and set the height accordingly, this way you are still with one layout with special drawable as background.
A customized LevelDrawable might do the trick.
I would layout this bar as follows:
A RelativeLayout as a container for the rest, with height set to wrap_content and alignparentbottom = true
An ImageView for the bar
2 Buttons with a transparent background (Button 1 and 2)
Button 3 is a custom Button with a custom Image of a trapezoid as background
So you will have a Layout similar to this:
<RelativeLayout
...>
<ImageView
.../>
<Button
... Button 1 />
<Button
... Button 2 />
<Button
... Button 3 />
</RelativeLayout>
I don't exactly know that this will work, and I can't test it, but you might give something like this a try; I believe it can all be done elegantly through XML.
Have a RelativeLayout (id:mainLayout) that will contain all of your views, wrap_content for both dimensions.
Have a blank View as your first child that will serve as your background bar
Set the View's background color/image to what you want; layout_width to fill_parent; layout_height to wrap_content; layout_alignTop="#id/leftButton"; layout_alignBottom="#id/leftButton".
Add an ImageButton for your center button (id:bigButton), wrap_content for both dimensions; layout_centerInParent="true".
Add an ImageButton for your left button (id:leftButton), wrap_content for both dimensions; layout_toLeftOf="#id/bigButton"; layout_centerInParent="true".
Add an ImageButton for your right button (id:rightButton), wrap_content for both dimensions; layout_toRightOf="#id/bigButton"; layout_centerInParent="true".
In my head, I believe this works, but I could be off. Regardless, something to think about, and I hope it helps you find a solution. :)
Better you can tablelayout with different button styles or relative layout for button "3"