React Native justifying views vertically without me setting it to - android

I'm experimenting a login screen: https://snack.expo.io/#lucaszanella/login-screen-test-zanella
(some image sources were removed because I cannot upload them to snack and others I changed to random images from url)
Open login_screen/components/Form.js. Well, as you see, the UserInput inputs and SubmitButton button are spaced, but I didn't tell them to. I already tried all justifyContent properties and they don't even move the components. Looks like they are justified (not even equally).
What is going on? If you know some concept about flexbox that I'm getting wrong please tell me.

Children of a flexbox share the parent's flex area in proportions. You have set Logo to flex:3, Form to flex:7, and SignupSection to flex:1. Thus, 7 + 3 + 1 = 11, therefore, Logo takes 3/11, Form takes 7/11, and SignupSection takes 1/11 of the parent's flex area in the specified direction.
Within Form, you've set UserInput to flex: 1. So the children (UserInput) of Form will equally share (and fill up) the flex area (7/11) that Form has acquired from its parent. This is why you see the space between UserInputs. To understand this better, try replacing UserInputs with simple Views with different background colors and you'll see what's going on.
Solution: Reduce flex on Form and apply margins if required.
EDIT
Alternatively, you can set fixed height (in case of flexDirection:'column' of parent) or width (in case of flexDirection:'row' of parent) to the children.
Hope this helps.

Related

Responsive Layout in XML

Which is the best option to create a responsive layout design? The first question is what should be the height and width of every view (it should be in percentage, match constraint or wrap content using constraint layout).
If we use wrap content I think there is no way to create a responsive design with help of wrap content because if content increase the view will take all the space of the screen either vertically or horizontally
If we use match constraint then, in that case, it's good, but sometimes it is looking awesome on Android Studio but when we run it on a real device it doesn't look the same
The last option is to use percentage, in that case, I think first we have to check our item list vertically and horizontally and provide them space according to their content priority and usage
So what will be the best case to create a responsive layout in XML for Android?
It depends on UI.generaly people use the 2nd and 3rd methods because by using constraints and percentages you can get responsive UI.
sometimes it depends on your requirement.
if you are using the percentage method and you set the imageView at 10 % it's looking proper on your device but sometimes it happened that in a small device that imageView is not looked proper
So the moral is all your three methods can be applied as per UI you can not make all designs responsive using 1 method

DP and Scaling with devices and AutoLayout iOS swift

I am migrating from Android to iOS (Swift). In Android UI elements are scaled up or down (height and width using "dp", layout_weight e.t.c) according to device size.
However I find this VERY difficult to achieve with Auto Layout's constraints, I want the elements in my UI to scale according to device size.
For example, in the shared image below, asides the compression of images to fit the screen width, every UI element has the same size, only looks like UI elements have been duplicated with same specs on all screens
This might help others in their migration from Android to Swift
(I only pinned the width of the 2 ugly ImageViews below)
P.S: This is what I'm trying to replicate guys, this view to fit properly on all screens. Sorry for the blur, I'm not in charge of this project
There's a zen to the AutoLayout. Let me see if I can give you some direction.
You'll want to test every UI on the smallest simulator available (iPhone 4S). This will let you know if you need to adjust your elements' minimum size.
Now for a top-to-bottom review of your UI posted:
"Profile" looks fine
To make the top-left and top-right boxes resize with screen size, you'll
want to give a constraint to the superview on left and right sides respectively. Then you'll want to make a horizontal constraint between the two (to maintain a space between them. Then you'll want to set them to equal widths. You can also set aspect ratio constraints for each one.
Your forms look fine. I can give more guidance here if the look you're after doesn't match the image you posted.
For the views below the form, you'll probably want to follow #2 above.
As for the height issue, set a constraint from your bottom view to the superview's bottom. There might be crowding, interface builder might yell. Chances are, you'll need to set the horizontal spacing constraints from = to >=.

Dynamic Layout android

I'm new to Android and it seems that I cannot find the right layout for my problem.
I have a bunch of buttons (also added dynamically during the execution of the app) that I want to display in a column.
I have used a LinearLayout (Vertical) and it does the works pretty well in a tablet. The problem is that on smaller screen, like phones, there's not enough space to visualize all the buttons and half of them are not shown.
Is there a layout that allows me to do either something like "show all the button in a column, and then when there's no more space, start piling up in the next column", or something that allows it to resize the buttons in order to fit them all onto the one column?
I have tried with GridLayout but with no success (i.e. even setting the android:columnCount=3 I didn't notice any change)
Any ideas?

How to change a view position and size at will

I am working on an Android Advertisement SDK. This SDK will charge fetch Advertisement resource and play it in a WebView.
Depending on the content of the Advertisement, the SDK need to change the WebView's position and size. For Example, A banner advertisement will palce in the top or bottom of screen, some advertisement maybe place at center, left or right.
Now I need the users to place the WebView in FrameLayout, So I could change the position and size of WebView at will and don't affect other views. I could set FrameLayout.LayoutParameters to adjust position and size.
Obviously, this is a strong restriction for users. Maybe they want use RelativeLayout and others.
So is there anyone have ideas about my issue? I am trying to use fragment now and didn't know would it work.
There is 2 approach to do this.
One is to set a layout ( forgot the name ) which allows you to set a component at custom position, size anywhere you want. As I remember it was 2 of those and one is deprecated form a version of Android. Google it those please, if you choose this method.
Other one it is with a trick:
Establish 9 positions (like the 9 pinch) and there use a predefined layout.
For eg. use a Relative layout.
1. if the banner need to be in position 1 than do x,y,z stuff - rearrange a bit the others, do what you need if is on the top left.
2. if the banner it is a "merged position" 1 and 2 from grid (a a lot wider), than you do other corrections.
and do many cases what you need.
Good luck
I have figure out this question.
Every android app is base on a FrameLayout(android.R.id.content).When I need to change position of a view. I could remove the view from its current layout and add it to FrameLayout(android.R.id.content).
That's what I want.

Android WebView scrolling within ScrollView

Very general question: I have multiple widgets in a ScrollView Android app. A standard ScrollView, mobile can show say 720 lines and user can scroll down then back up going thru multiple widgets (text panes, buttons etc). Problem is that I want to add a WebView that will display an HTML table; the height of this HTML table will be variable size.
Is there a way to change the height of the WebView based on the size of the HTML table it should display?
Yes, you can get a reference to the WebView, then set the height of it, with the setHeight attribute.
Maybe you would be better off letting the container take care of that for you, and set the attribute to "wrap_content".
I guess, you need to calc web-view content size (here and here and enter link description here), than set webview size to content fits (maybe here). In that way you should have only scrollview scrolling.
Good luck

Categories

Resources