I have added in a Relative Layout some ImageViews with some Buttons and gave them some width and high values.I have tested the application on a nexus 7 and everything looks great but when I tested on other devices some functions like a popUpWindow or even some Views look wrong.Is there a way how to resise a layout with all his views dynamically to fit every device I test on ?
The values you're using are probably not what you're looking for. Instead, you may mean to use wrap_content or match_parent.
Please have a look at this tutorial on layouts and absorb and practice some of that before immediately asking for help. You got this!
Related
I created new login page in android studio. that activity xml looks good on Emulator but in real time mobile its looks like irregular alignments what can I do for that? I used Linear layout for that.
The most efficient solution is to use ConstraintLayout.
ConstraintLayout has a flat view hierarchy, unlike other layouts, so it performs better than various other layouts. Only a single layout can handle your UI.
Or you may use a RelativeLayout, and then use LinearLayout as a child inside RelativeLayout, i.e., you will need to create a hierarchy with some nested views, which will adversely affect performance.
Most probably you hard-coded pixels, try converting to ConstrainsLayout. 1 LinerLayout can not provide enough flexibility if the layout is not simple.
I have started to dive into the Constraints Layout that were announced on the IO this year. This looks very promising and makes your layouts very efficient. I have seen the codelab excersize provided by Google. However I have the following questions that I would like to resolve.
How can ConstraintLayouts be used to design the layout for different screen sizes?
Currently I design the layout and set the views' margins and paddings etc for a specific device/screen group. Save those values in the dimens.xml file. This is a REALLY painful method to design the layouts. Does the Android ConstraintsLayout mimic the AutoConstraintsLayout of iOS in designing for multiple screens as well?
Does designing the Layout for different screen orientation still need different Layout.xml files i-e; layout_landscape.xml and layout_portraint.xml?
Yes, the entire point of ConstraintLayout (and for that matters, any Android layout since Android 1.0) is to be able to handle different screens (dimension, density...). You have nothing special to do (other than specifying constraints between widgets).
If you want to design for different screen sizes, think about margins as "minimum" spacing; and create constraint between widgets so that you position widget relative to other widgets.
You also have guidelines and bias centering, which give you a lot of flexibility.
Regarding the screen orientation, it is entirely up to you -- if you do nothing, the layout you define will be applied on either orientation. So, it would "work". But often, you want a different UI between portrait and landscape. In that case, you can indeed create two layout files, and the usual system will pick the right one for you.
Finally, you can easily test how the layout you are working on would behave in a different screen/device by changing the current screen definition from the popup in Android Studio:
You can also use the resize handle to see the layout to an arbitrary screen dimension.
How can ConstraintLayouts be used to design the layout for different
screen sizes?
If by different screens you mean phone and tablets then you have to create different layout for them. one way to do it is to define layout-sw360dp,layout-sw600dp and layout-sw720dp.
Currently I design the layout and set the views' margins and paddings
etc for a specific device/screen group. Save those values in the
dimens.xml file.
You might wanna look into chains and guidelines.
Does designing the Layout for different screen orientation still need
different Layout.xml files i-e; layout_landscape.xml and
layout_portraint.xml?
Yes.
So I have a question about best practice for dynamically creating and sizing buttons within a ViewPager, based on a changing external state.
Essentially, I have a scrolling view and I want my ViewPager to contain a number of buttons of a specific size and count depending on what part of the scrolling view is currently visible.
My question is about deciding the best implementation of this feature, I see two options: would it be simpler to
Constantly create and scale new buttons whenever the scrolling view moves
Make the viewpager itself contain a scrollview and fill it with all of the pre-scaled buttons on app startup. Then, whenever the user scrolls the main scrollview the viewpager's scrollview (which contains the buttons) will scale programatically
Any ideas on which would be the simpler and more robust system?
Not much of an answer but I will leave a comment for ya! Basically you can do it either way, both aren't to difficult to accomplish, however I would probably go the dynamic route because it will always scale correctly. Doing a set amount will only work until devices become larger, or if you are targeting tablets or tvs then it will start to become extremely messy in the xml file for the layout. Dynamically adding also gives you far more control and saves time later on, you can simply change a number and have 100 more then going through and manually adding even 10. Hope this helps!
I have a vertical LinearLayout which has two another vertical layouts inside. The first one is always shown, and the second one depends on some event. I do want to animate that second layout when shown. How can I do it smoothly and nice? Thank you so much,
You should check out this library on Github. It may help. It is an animation library for listviews.
ListViewAnimations
A very simple, yet elegant way to get your layouts animated is by using the android:animateLayoutChanges="true" on its parent. This will likely take a lot of work in getting a nice animation out of your hands, unless you want to customize it.
With KitKat, Google introduced the android.transtion API, which may also be worth looking at.
You can create your own animation and you apply that animation to your layout when you need(In your case at the time of shown your layout)
yourLayout.startAnimation(yourAnimation);
i'm making an app that requires indefinite textviews and images. i'm trying to implement a Pulse News app UI but having a hard time implementing one. so i thought of an idea to make a UI like that with the use of textviews, imageview and horizontal scroll view.
textview string values are from parsed xml online and images or the imageviews will be images from a specific directory in the sdcard that my app is using.
can anyone give me ideas how can i do it without using an xml layout or is there any or other options or ways for doing this? thanks...
You can create a viewgroup with one textview and an image. Then it can be added dynamically to your layout many times. This can be done by creating objects in a loop. You can change the content in each viewgroup at the time of inflation.
though i dont know what exactly how pulse new app looks like, but by going through your question (horizontal scroll view in particular) I guess you want to implement a "Gallery" type implementation where in you can swipe left/right on page basis.
If my assumption is correct then you will like to see to ViewPager of android backward compatiblity pkg.