Scroll view (basic 4android) - basic4android

What code you have to write the scroll
view b4a be coordinated with some
text labels
This means that if the text is too long
scroll set up the same amount ?

Are you referring to the layout not scrolling down since you have lots of labels which are out of view? If so, use this reference.
just simply replace the scrollview layout to your parent layout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
// Write something
</LinearLayout>
</ScrollView>

Start with defining label size (particularly the height). If your label size for example is:
Dim intLabelSize As Int
Dim intScrollHeight As Int
intLabelSize = 50dip
you have to figure out if the labels number is static or dynamical, also how much space there would be between labels.
If the number of labels is static (for example 4):
intScrollHeight = ((labelheightdip+spacedip)*(numberoflabels+1.5)) + 5dip
Without 1.5 labels and scroll are not visualized correctly on different size devices, you can play with this index according the results.
intScrollHeight = ((intLabelSize +10dip)*(4+1.5)) + 5dip
However, more common case is to write the code based on dynamic number of the labels. Very easy way to obtain the number of labels is with scrollview.Panel.NumberOfViews
intScrollHeight = ((intLabelSize +10dip)*(scrollview.Panel.NumberOfViews+1.5)) + 5dip
Then you have to scrollview height:
scrollview.Panel.Height = intScrollHeight
This way the height of the scrollview would be dynamic and dependent on the number of the labels and their size.

Related

Set Button half the window size in .NET Maui

I'd like to set the size of a button in .NET Maui to take up half of the window size, or some other fraction. I want to have some big buttons, and I can not lie. If I was doing this in html/css, I would set the width to 50%. In .NET Maui, I would think that I would set the widthrequest to 50%. There doesn't seem to be a way to do that because .WidthRequest only takes a double. So, I thought I would get the width of the current window. I try
var width = DeviceDisplay.Current.MainDisplayInfo.Width;
That only seems to return a zero when I try this in windows in debug mode. Googling doesn't seem to be much help. Is there a way to set a button to a width?
TIA
Maui has proportional sizing for grid row and columns. You don't explain where you want your button but you can use multiples of * proportional.
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/layouts/grid?view=net-maui-7.0
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
If you put a button in that middle row then it will be half the width of the grid and central.
Similarly, define 3 columns with * widths and you have a central cell half the width and half the height of the grid.
I test the code and it work well:
<Button                
x:Name="btn"                
Text="btn"/>
double width= DeviceDisplay.Current.MainDisplayInfo.Width/4;    
public MainPage()
{        
InitializeComponent();        
btn.WidthRequest=width; 
}

How to make other element in scroll adjust when an item has a child?

Hello, any advice how to make 'obj#2' move down or adjust when for example obj#1 has a childs?
for the mean time some child or the 1st child of Object#1 is overlapping with Obj#2.
goal is:
obj#1
child0
child1
child2
obj#2 <-----
my hierarchy setup is:
scroll_view <---scrollrect,mask
  content <---vertical layout group, content size fitter
    [[obj#1]]
      sub_content<--- vertical layout group, content size fitter
       [[obj#1 child0]]
       [[obj#1 child1]]
    [[obj#2]]
    so on...
I've played around with the settings/options and searched for a video tutorial but most of the one I get are single elements list in scroll view only.
Thank you for reading. Regards.
You can use Content Size Fitter on obj#1 with Vertical fitting, but you should add Layout Element to you child’s(child0, child1, child2) and setup preferred height. But you setup must be identical, if you setup Min Height in Layout Element, use Vertical Fit - Minimum, or Preferred, when use Preferred Width
EDIT: oh, I see you use Content Size Fitter, but if you haven’t Layout Element component on childs, Content Size Fitter can works unpredictably. And, try to add Vertical Layout group on Scroll View, this may help to control vertical position of the elements according to the size

Make intrinsicContentSize adapt to external constraints

The Context
I often have situations where I want multiple NSTextViews in a single NSStackView. Naturally, Auto Layout is not pleased with this since this makes height ambiguous (assuming the stack view is not set to fill equally). Even after adding constraints to resolve these issues, macOS Interface Builder appears to have a bug where it refuses to actually update frames when asked.
For this reason and others, I'm attempting to create a TextBox class (subclassing NSView) to encapsulate an NSTextView (and associated scroll view) and include an intrinsic content size to avoid layout issues. The intrinsic content size would be calculated based on a user-specified min and max number of lines (to display without requiring scroll). In other words, up to a certain max number of lines, TextBox will resize itself so that scrolling is unnecessary.
The Problem
This would seem to require an intrinsicContentSize that is dependant on frame width.
But, intrinsicContentSize documentation states:
The intrinsic size you supply must be independent of the content frame, because there’s no way to dynamically communicate a changed width to the layout system based on a changed height.
However, Auto Layout Guide states:
A text view’s intrinsic content size varies depending on the content, on whether or not it has scrolling enabled, and on the other constraints applied to the view. For example, with scrolling enabled, the view does not have an intrinsic content size. With scrolling disabled, by default the view’s intrinsic content size is calculated based on the size of the text without any line wrapping. For example, if there are no returns in the text, it calculates the height and width needed to layout the content as a single line of text. If you add constraints to specify the view’s width, the intrinsic content size defines the height required to display the text given its width.
Given that when scrolling is disabled in a text view:
If you add constraints to specify the view’s width, the intrinsic content size defines the height required to display the text given its width.
Then it seems there is a way to do what I want by perhaps looking at existing constraints.
The Question
How can I define an intrinsic content size that calculates height based on otherwise specified width, as described in the last quoted sentence above?
The solution should produce the effect described in "The Context" and not produce errors or warnings when used inside a Stack View.

GWT DockLayoutPanel with browser determining size of some subpanels?

It looks like you have to specify absolute sizes of all but one subpanel. For example, from the GWT docs:
DockLayoutPanel p = new DockLayoutPanel(Unit.EM);
p.addNorth(new HTML("header"), 2);
p.addSouth(new HTML("footer"), 2);
p.addWest(new HTML("navigation"), 10);
p.add(new HTML(content));
But I want the north panel sized by the browser. I put some text or buttons in it and I don't know exactly what size it will be, I just know it is relatively thin and at the top of the page. And I want the content to take up the rest of the space, but no more, so there are no browser scroll bars. Is there a way to handle this with these newer layout panels?
Right now I'm using the older panels, and I have a handler attached with Window.addResizeHandler, which sets the height of the main content area so that everything fits within Window.getClientHeight
Update:
Thomas suggested a DockLayoutPanel inside a HeaderPanel, but this is not working for me:
<g:HeaderPanel>
<g:Label>Header top</g:Label>
<g:DockLayoutPanel unit='PX'>
<g:west size='300'>
<g:Label>West</g:Label>
</g:west>
<g:center>
<g:Label>Center</g:Label>
</g:center>
</g:DockLayoutPanel>
</g:HeaderPanel>
"Header top" is there, the rest invisible. It looks like inner divs are getting 0 height.
You should put a DockLayoutPanel (for the west and center regions, possibly the south one too if you don't want it to use its natural height) in a HeaderPanel (for the natural sizing of the north region)

How to let a GXT grid take up all available width?

I have a grid in GXT, something like this:
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig config = new ColumnConfig();
config.setId("type");
config.setHeader("Type");
config.setWidth(50);
configs.add(config);
config = new ColumnConfig();
config.setId("text");
config.setHeader("Info");
config.setWidth(75);
configs.add(config);
columnModel = new ColumnModel(configs);
listStore = new ListStore<DtoModel>();
grid = new Grid<DtoModel>(listStore, columnModel);
grid.setAutoHeight(true);
grid.setAutoWidth(true);
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.setLayout(new FillLayout());
verticalPanel.add(grid);
This creates the grid just fine with one exception-- the width is limited to the sum of the column widths. When I forgo the column widths, the grid ends up having 0 width.
Is there a way to have this grid and its columns expand to fill the entire area available to it?
Edit: One of the difficulties is the ColumnConfig.setWidth() method only takes an int as a parameter, so I can't specify "100%" as a string or something like that.
This is the way to do it:
grid.getView().setAutoFill(true);
Here is a key point to remember: With setAutoFill() when you resize a column, gxt will always resize all other columns so that the grid continues to fit the container. Without autoFill, if you just use the autoExpand column, if you resize one column, the grid could grow bigger (or smaller) than the containing component and in such a case you have to manually resize the grid to fit - which is not only a pain, it is almost impossible for the end user in most cases.
There is a function in GridView that forces all columns to fit to the availiable space. It is like setting a flex of 1 to every column.
grid.getView().setForceFit(true);
The GXT Grid has a method named setAutoExpandColumn() that will take id of the column that you want to take up all available space in your grid. I would remove the setAutoHeight and setAutoWidth from the grid.
I am not sure if you are trying to achieve a fixed width layout or flexible layout that will expand based on the height/width of the browser. Here's what I typically do as I want my grids to take up all of the height and width and scroll on the page. Hope this helps.
--Vinny
Viewport viewport = new Viewport();
viewport.setLayout(new BorderLayout());
ContentPanel center = new ContentPanel();
center.setFrame(false);
center.setLayout(new FitLayout());
center.add(grid);
you can try to style the grid/columns with css (setStyle/setColumnStyleName) and then you can use 100% as width.
cupakob
May be it's too late for now, but I tried to set grid's autoHeight and autoWidth properties to false, combining it with setting autoExpandColumn (I didn't need to change default autoFill's value).
grid.setAutoHeight(false);
grid.setAutoWidth(false);