We have a case where we pop three different fragments into a container based on user interaction. The fragments differ in height as indicated by this graphic:
We use transaction.add(R.id.framelayout_main_container, frag).commit(); to add a new fragment, if Fragment frag = getSupportFragmentManager().findFragmentByTag(frag_tags[fragNumber]); was null and transaction.replace(R.id.framelayout_main_container, frag, frag_tags[fragNumber]).commit(); when the frag was !null.
When viewing Fragment 2 or Fragment 3, there is almost always extra space at the bottom. If the extra space is added to the height of either Fragment 2 or Fragment 3, it matches the height of Fragment 1.
How do we permanently get rid of the extra space in the Fragment container for the shorter fragments?
Related
I'm designing a prototype cell in Interface Builder. Another programmer built the previous cells in Storyboard before me, I'm just adding the new one in image 2 with the [Some text] label. Both cells have the same class set in interface builder, a custom UITableViewCell subclass.
Existing cell: has leading space to superview = 10, but somehow the constraint is pinned to some floating point in space (there is no parent view other than Content View).
My cell: has leading space to superview = 20, but it pins the edge to the actual content view superview. If I set it to 10, they will look way different, but on paper have the exact same layout constraint (leading space = 10 to superview).
So it looks almost as if there is some sort of invisible edge inset, or layout margin, but I don't see any properties in interface builder that could affect it. Any ideas?
The solution turns out to that you need to use the bottom toolbar button to be able to constrain your leading edge to the superview margin (with the checkbox). I was using cmd + click and drag menu, which is why I couldn't find it. Doing this in a UITableViewCell subclass pins it to a margin.
We have a table view with prototype cells in a storyboard that work well in iOS 7 to 9. The content of the cells is layed out with AutoLayout.
In iOS 10, the prototype cell does not display its content. The cell is black.
If I run the view debugger and show the clipped content, I see the cell's content being shown. Part of it is within the cell's bounds, part of it outside. Even then, the content's position does not correspond to the layout constraints.
Also, when looking at the view hierarchy on the left hand side of the view debugger, I can see that the cell has no children.
Deleting this line fixed the issue:
expiryDetailsTableViewCell.translatesAutoresizingMaskIntoConstraints = NO;
I know I can fix this programmatically and I know I could set the text to tighten / scale but I would like to know how to get this text to extend organically to a third line on small screens. How can I accomplish that?
There are a couple of things you need to take care of before your label grows:
Make sure the 'number of lines' field in the attributes inspector is set to zero. Setting it zero allows the label to grow depending upon the content it has.
If the label is in a container view, make sure you haven't specified the height constraint explicitly on the container view. Since the container view should generate its height from its subviews and the subviews will generate their height from the content they have. Its sort of a chain process that goes on if you have a deeper hierarchy.
Make sure there is no sibling view to the container view with an explicit height that might cause your container view to shrink while maintaining its own height. This point may also apply even if your label is not within some container view.
In the image below, the container view(gray one) is bound from three sides allowing it to grow from the bottom.
Below image shows the constraints applied to the content views of the container. The container is driving its height from its content views.
Below I have increased the text of the label from a single line to three lines. At this point the label tries to expand horizontally but since the container view is bind with the super view on both sides the label has only one direction left to increase itself. It increases downwards pushing the textfield and button down and since the button is tied with the bottom of the container view it pulls the container view increasing its height.
JavaFX 8:
I have a TableView. I want to let users decide the column width either with the mouse (column.setResizable(true)) or with a dialog, where they can manually input the number of pixels. This all works, but here's my problem:
Sometimes, the prefWidth and the Width of the column differ. In particular, if the user manually resizes the column and then uses the dialog to input a pixel width which is minor than the manually set width, the width doesn't change even if I call setPrefWidth. The code is correct, because the prefWidth is correctly set (I read them using getPrefWidth and getWidth and they don't match after using setPrefWidth).
For example, the prefWidth will be 200 and the actual width 100. But I need to give my users the chance to change the width in both ways, in any order.
How can I achieve that?
I'm developing an app with a complex hierarchy of widgets and layouts, but in short it has a central widget with a formulary as upper widget and a QScrollArea as buttom widget (by means of a QVBoxLayout).
That QScrollArea represents a list (grid layout indeed) of QPushButtons which can contain a huge number of buttons (or not).
I want my app fits the following constraints:
Both (form and list) consume all available horizontal space, redistributing its contents to fill all horizontal space (nor SpaceItems neither contents margins).
Both must save as vertical space as possible, in order to make "lines" close to each other.
I've solve partially my problem making use of setSizeConstraint(QLayout::SetFixedSize) on the form, which shrinks it vertically, but also horizontally, causing that both, list and form, have different widths, wich doesn't look like very well.
How can I achieve that? I mean, how can specify something like grow horizontally to fill the widget but shrink vertically has much as possible?
Add a spacer as the last item to the layout:
gridLayout->addItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Expanding), lastrow, 0);
I think this is what you want:
If you know how many columns you will have (and it doesn't change), insertStretch() in the last column (although it might give you the same effect as using a spacer).
int columnCount = gridLayout()->columnCount();
gridLayout->insertStretch( columnCount(), 1 ); // Default stretch for other
Note that this will resize your buttons to the size Qt thinks they should be unless you are explicitly changing their widths.