BottomNavbar breaks when you add more than 3 elements - java

I am working on an android application and it was agreed to only have 3 fragments in its bottom navigation bar. However, things have expanded and we decided to add another fragment. When adding the 4th fragment, the dimensions of the container break making it look like this.
This is my xml code.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#drawable/selector"
app:itemTextColor="#drawable/selector"
app:menu="#menu/menu_navigation" />
I have tried different properties to make it stretch but they end up putting it only to the right and not expanding left or vice versa. For instance if I was to try using wrap_content on the layout_width, the container would glue itself to the left.
What is the needed property that might be a solution to the problem?

It's an automatic measure in order to not have labels overlap.
You can make a quick fix by adding app:labelVisibilityMode="labeled" to your xml.
Note that you should use Use Support Library 28 for this.

Related

Android, should I center content?

I'm pretty new to android and wanted to ask about the centering practices, what I mean is that for example:
Before I say something, I don't know what are the good practices are so...
I can have a LinearLayout with height as match_parent and android:layout_marginTop="?attr/actionBarSize"(btw, according to google's material 56dp).
So that is one option, but, I saw apps where the content is centered nicely if the device is really long(such as Galaxy Note devices), so what I did is:
Same LinearLayout but with height as wrap_content and android:layout_gravity="center", but the problem here is with for example a form with 1 field(almost no content height), the problem is that almost no content will leave you with a lot of space between the toolbar and the content and below that content as well.
My question: altought may be obscure I'm asking for the best practices, what is the best approach that will make content(bigger or smaller) appear nicly on multiple devices, maybe it would require multiple layouts/dimens, I'm ok with that, just looking for the right path.
There is another view group named RelativeLayout.
You can use it like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
// here you can use attributes such as `android:layout_below`, `android:layout_above`,`layout_toRightOf`
//to modify and control your items
/>
</RelativeLayout>

Scroll behavior of Flexible Space in Android

To prevent from re-posting all my code again, it can be found in this question.
What I'd like to do now, is to prevent the upper imageview from shrinking upon scrolling; instead, I'd like to make it 'static' so it won't scroll up and shrink when the lower view is scrolled over it.
I'll add some pictures to compensate for the loss of clarification.
This is how the screen looks at it's fullest size:
This is how it looks when it's shrinked:
This is what I want:
Edit:
Forgot to mention what I tried and didn't work. Tried playing with the collapseMode of the ImageView which appears not related.
Also tried playing with the scrollFlags attribute of the CollapsingToolbarLayout, removing flags and adding enterAlways, but none worked. I have no clue on how to achieve this effect.
This simplest way would be to set the parallax multiplier to 1:
<ImageView
android:id="#+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1" />

Android Vertical Switch Widget

Using android, I'd like to get a vertical switch widget implementation in place. As far as I can tell, it looks like switches only have a horizontal orientation. I'd like to have something like the following:
After looking through the threads here and searching google, I have yet to find something that can give me this. Everything I search for gives me the horizontal implementation only.
so I can generate your typical horizontal switch
<Switch
android:id="#+id/switch_button"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/label"
android:layout_gravity="center"
android:switchMinWidth="130dp"
android:thumb="#drawable/switch_selector"
android:track="#drawable/track_selector" >
</Switch>
but there doesn't seem to be a good way to set the orientation. I know that the question is a bit high level. Is there some attribute that is immediately available that will allow me to have a vertical switch? Or will I have to create a custom switch and possibly modify the onDraw method so that it is flipped vertically? Any help is appreciated. Thanks.
Try android:rotation="90" like this:
<Switch
android:id="#+id/switch_button"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/label"
android:layout_gravity="center"
android:switchMinWidth="130dp"
android:thumb="#drawable/switch_selector"
android:track="#drawable/track_selector"
android:rotation="90">
</Switch>
There is no quick attribute for vertical orientation.. Sorry :)
First you can look at the code of the switch and see if you can copy and manipulate it.
Second you can just implement your on. Have a layout with a button inside it. use onTouchListener to slide it from side to side. No need to use "onDraw".
Try toggle button witch graphics and use pictures like this You included in Your post. Here is example of such toggle buttons: Toggle button using two image on different state

How to position a button exactly how I want it?

I'm using RelativeLayout. I understand using Graphical Layout you can't position a button too well. How can I do it in XML? I've tried changing the marginLeft, but nothing moves.
All I want to do is position my buttons!
<Button
android:id="#+id/ListsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/EditButton"
android:layout_alignBottom="#+id/EditButton"
android:layout_alignParentLeft="true"
android:layout_marginLeft="18dp"
android:text="Li" />
You can use marginLeft, marginRight, marginTop, and marginBottom for small adjustments. If you want to do larger adjustments you can use blank elements in combination with weights, or use a RelativeLayout in combination with alignParentBottom, alignParentTop, alignParentRight, and/or alignParentLeft
If you are beginner in android programming then I would recommend using graphical layout since you won't know every attribute for positioning and styling your views. You can see #Freelancer answer to see how many attributes you have to consider while positioning any view correctly.
Using graphical layout is very easy once you get a little hang of it. You can use Relative Layout which will help you moving any view like button or textView wherever you want. Direct xml coding will require some skills that you will no doubt get in time.

How to create a Layout were I can place anything where I want?

I'm designing an app with many images, buttons and textViews strewn across the screen. At the moment I am using the relative layout as it seemed the most flexible of the lot. However were I place my elements and their size is still restricted to being aligned with other elements. Even worse if an element changes size any elements aligned to it will also change size.
There must be a simple solution to this! Apple's nib files perform this so easily with an effortless drag and drop to any location; yet android appears to be stuck with restrictive table/linear/relative/grid layouts.
If possible can the solution be performed via eclipse. If not please guide me to the relevant documentation to learn to create my own layouts via xml, create a huge grid layout or whatever horrors await me :)
Thanks
I think what you want is something like an absolute layout tho these were deprecated a while ago, Im pretty sure you can still do this via a Relative layout, you don't necessarily need to align the via with another view, I guess you could just do something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="70dp"
android:layout_marginTop="82dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="172dp"
android:layout_marginRight="84dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
all I'm doing here is aligning it with the side of the parent and having a margin between it
You can do what you ask with a Frame Layout and setting the position of each object. But do so at your own risk. The reason Apple nib files let you arbitrarily place objects is taht the aspect ratio of all their devices is the same. So your layouts just scale up and down evenly.
Android is a more diverse ecosystem, and you should try to embrace layouts that adapt to different screen sizes and orientations.
Take a look at Android custom layout and Android - How to draw a letter at a specific point?
Are you planning to only use the app on a single android device model? If yes, check AbsoluteLayout's Alternatives. (FrameLayout or RelativeLayout)
It's not a good idea to put "Anything Anywhere you want" since Android devices have a lot of different screen sizes and properties. The only option would be to define your own custom layout.
I actually really like the way Android tries to make your layout compatible with as much devices as it can using alignment and structured layout views.
The reason it's simple for Apple is that you're only targeting iPhone, which has a fixed screen properties accross all devices.
Hope it helps. Good luck.

Categories

Resources