I am using auto layout in my project when i trying to scroll a view and add constraints then it shows warning or errors please suggest me how to resolve it.
Use scrollview and put your view inside that scrollview.
ScrollView - Apply constraints of x position,y position,leading & trailing space. don't give constraints of height and width of scrollview.
View - Apply constraints of x position,y position,leading & trailing space, width and height.
You first develope your whole layout. then put that layout inside a scrollview. Remember that a scrollview always takes only one layout and cannot take more then that. so remember to design your page in a manner that there is only one outer most layout and then put that whole layout inside ScrollView.
If you want only part of your page then put the elements that you want to scroll inside a layout and then put that layout inside a scrollView.
<ScrollView>
<LinearLayout>
//the whole page
</LinearLayout>
</ScrollView>
<LinearLayout>
//some elements
<ScrollView>
<LinearLayout>
//elements to be scrolled
</LinearLayout>
</ScrollView>
</LinearLayout>
Don't worry About it .Just make sure constraints are enough (no matter in your xib or code).SomeTimes I need to Conatraint my Views in scrollView which base on scrollView's subViews
Related
I want to take a container, in which I want to add some view like recycler view and list view, but in recycler view, the view gets recycle, But what I want is that I want to adjust the view in line like if view width is small, then more view can be put in a single line and if view width is big then less view will come. it will be adjusted by view width. Please help me with how can I achieve this functionality in android.
You can use constraint layout, create constraints views using "match_constraints","match_parent","wrap_content" for size.
Try using scalable sizes for margins and let Android scale it accordingly.
res/values-hdpi/dimens.xml
res/values-xhdpi/dimens.xml
Good morning, this is actually my first question on StackOverflow after a few years in the industry (hope it's not too late!).
I'm working as a side project on a react native app.
I fail to understand how does the view change when the keyboard is up.
When the view shrinks (because the keyboard was shown), views overlap one to another. I want them to still be split.
I have this picture showing what I mean with overlapping views:
I thought it might be something with the paddings/margins, but I removed them all and still the same issue. Now, I know that the input height is defined by an absolute number, and that is what makes it not shrink, so it is bigger than the actual view, that's why it overlaps.
How can I keep my input having a fixed height but also maintaining a margin of separation when the view shrinks ??
Thank you very much!
Edit: I'm editing because I feel like I haven't been able to express my idea of how I need it to work. (Should I delete previous explanation? Keep picture if someone edits and deletes the first explanation).
The initial view with no keyboard has to be like this:
The inputs and buttons have to be at the bottom, the view getting all the height possible.
When opening the keyboard (by clicking on one of the inputs), I want the list to shrink so that the buttons and inputs are still visible and separated by a small margin/padding, and the list to have taken the remaining space (again respecting a small separation between views). The list will still be scrollable (it is a FlatList) when opening the keyboard.
Thank you again and sorry for the misexplanation.
You can try wrapping your content inside a ScrollView instead of a normal View like this:
<ScrollView style={{flex: 1}}>/* your content here */</ScrollView>
So when the keyboard shows up your elements won't overlap since they take the same space but you can scroll to see the elements hidden by the keyboard.
I think you can try something like this:
<View>
<ScrollView>
<KeyboardAvoidingView style={{flex:1}} behavior={Platform.select({ios:"padding", android:null })} keyboardVerticalOffset={Platform.select({ios: 0, android: 500})}>
{/*Your buttons and other elements here...*/}
</KeyboardAvoidingView>
</ScrollView>
<View>
You will also have to import KeyboardAvoidingView and ScrollView from react-native for this.
Without using code, I'm basically trying to achieve the "Desired outcome" in this picture:
I want the constraint on the "Hello!" label to shrink its length when the screen height is shorter.
As you can see in "Actual result", the Button in the bottom is off the screen. I want the image view to have fixed width and height.
I know I can create IBOutlets for constraints and doing it by code like this kind of posts suggest (autolayout - make height of view relative to half superview height), but I'm trying to avoid using code as much as possible.
Side question: If there's no way to do this in IB, what are the best ways to do this in code?
Thanks for the help!
Yes. The easiest way to have this kind of "split height" constraint is to put a "header" view between your image view and the top of the screen, and embed your "Hello" label inside this new header view. Then add a constraint to keep the "Hello" label vertically centered inside the header view.
To keep the header view the right size, add constraints to keep the top of the header view pinned to the top of the screen, and the bottom of the header view to the top of the image view.
Then you'll just add constraints to keep the button and image view pinned to the bottom of the screen. (Or, see comment from Sulthan, below.)
In Xcode 5.1 (in beta), there is UI to make more general constraints, including the ones you want, but you have to do it like this or in code in earlier versions.
I have a section which is scrollable horizontally with paging and other sections normal with vertical scrolling enabled in UICollectionView.
Now the thing is UICollectionViewLayout has contentSize property which is defined for whole CollectionView.
But I want only 1 section horizontally scrollable in vertical scrollable collectionViewLayout.
I know I can use another collectionView in a section to do this.
But can I avoid that??
No, the only way to do what you are trying to achieve is to use nested views. One way to do it is to use custom cells in a vertically scrolling UICollectionView, each of these cells contains its own horizontally scrolling UICollectionView. Presumably all but one of those will not contain enough cells to warrant any horizontal scrolling in that "row" of your outer view.
Since the outer view is vertically scrolling, you could use a UITableView for it instead of a UICollectionView.
I can't seem to make my segmented control, which is within a tableview smaller?
I'm not sure what fixed and the width, which is default to auto does?
I can't change the width from 320 either.
Heres a screen shot.
UIKit is going to resize a header view to be the full width of the table. Put the segment control in a view, and make that view the header view.
I find that when you put custom controls in a table view header or footer it is often best to place them on top of a separate UIView and make that UIView the actual header/footer.