In my Xamarin forms application, there are multiple ListView controls inside a ScrollView. But in android the scrolling is not working for ListView. Is there any alternative solution?
You SHOULD NOT include ListViews into ScrollView as it system will confuse scrolling behavior of those two.
You need to redesign your page with this in mind.
Example:
1) Use ListViews inside StackLayout
2) Use TableViews inside ScrollView
You can simply do with set 'NestedScrollingEnabled' property true for native side.
For xamarin forms you can create a custom renderer and set 'NestedScrollingEnabled' property true
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var listView = this.Control as Android.Widget.ListView;
listView.NestedScrollingEnabled = true;
}
}
ListView implements its own scrolling that might conflict with the ScrollView.
If you need to be able to scroll both lists in the same ScrollView you could for example create custom views (instead of using cells), placing them in a StackLayout inside a ScrollView
More about ListView performance, they even explain why you shouldn't place a ListView inside a ScrollView
Have you looked into using one listview with groups instead of multiple listviews?
I use any row of grid it will fix to that height & listview will not scroll
Related
I want to push (make visible) little part of master page to detail page like on pictures in links below. Is it possible in Xamarin.Forms?
Before swipe
After swipe
I'll be grateful for help.
Set
<ContentPage NavigationPage.HasNavigationBar="False">
Place a StackLayout or Grid that looks like the side menu shown in your image. Add a tap gesture recognizer to it.
slMenu.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() => ShowSideMenu(masterPage)),
});
private void ShowSideMenu(MasterDetailPage masterPage)
{
masterPage.IsPresented = !masterPage.IsPresented;
}
This is possible, but requires quite some work, since you can't access the width of the MasterDetailView directly.
In another post (see How to set width for MasterDetailPage in xamarin forms ) I have described how to change the width of the MasterDetail view.
While implementing that, I came across a behaviour like you want to have, though for me it was an error.
Basically the steps would be
Implement a custom version of the MasterDetail view where you can set up a custom width
Change the width of the master view so it is a bit wider than it should be
Adapt the calculations when collapsing and expanding the view so that they don't collapse the entire width
For instance if your Master View gets a width of 340 and you want the last 40 to show, make sure that when being collapsed it "only" moves by 300
I am having an issue with loading ViewCell in ListView in Xamarin.Forms application.
ViewCell is displayed correctly but only half of it. I tried to scroll down but I couldn't. The ListView ends loading but the ViewCell is designed to continue.
Thank you for your answers !
Take a look on ListView.HasUnevenRows Property:
To automatically size row height to fit content, the developer first
sets the HasUnevenRows property to true; and, second, either leaves
RowHeight at its default value of -1, or sets it to -1 if it has been
changed.
source
More details in official documentation.
Multiple ScrollView is not working on my content page Xamarin forms.so how to solve this?
i added two scrollviiew in my content page,but the second one is not scrolling.
Do not put a ListView inside a ScrollView.
Avoid placing a ListView inside a ScrollView for the following reasons:
The ListView implements its own scrolling.
The ListView will not receive any gestures, as they will be handled
by the parent ScrollView.
The ListView can present a customized header and footer that scrolls
with the elements of the list, potentially offering the functionality
that the ScrollView was used for. For more information see Headers
and Footers.
If you need more ListView on some Page you should use one ListView with Group.
I have a very simple Xamarin forms app which contains a scrollview, and inside is a stacklayout.
When deployed on Windows, the mouse works correctly to scroll the scrollview with a scrollbar. However, touch/drag does not work at all to scroll the same control. Do I have to do something special to enable touch/drag to scroll? I figured this would just work.
I'm not sure even where to start troubleshooting.
I am targeting Windows 10. Other platforms optional at this point.
The structure of UI classes I have is this:
ContentPage.Content = StackLayout1
StackLayout1.Children = { StackLayout2, Scrollview }
StackLayout2 contains an entry field and two buttons
ScrollView, which is the problem, contains another StackLayout
Inside that I have some labels and some grids
Following is a simplified repro. Running in the android emulator on my (touch capable) dev machine scrolling with touch works, running in the Windows 8.1 emulator, scrolling only works with a mouse, not with touch.
public App() {
StackLayout sl = new StackLayout();
for (int i = 1; i < 20; i++) {
sl.Children.Add( new Label { Text = "Label1", FontSize = 50, HeightRequest = 100 } );
}
ScrollView sv = new ScrollView { VerticalOptions = LayoutOptions.FillAndExpand };
sv.Content = sl;
ContentPage cp = new ContentPage();
cp.Content = sv;
MainPage = cp;
}
Does Xamarin not handle Windows devices with touch, like Surface or other windows tablets? Or?
There is an overriden method from Activity which is: public boolean onTouchEvent(MotionEvent event)
This is the general method that interprets all the touch events from the whole screen.
As you know every View has its own onTouchEvent() method that you could implement in order to add some custom implementation.It appears that these touch events go from the "inside" elements to the "outside" elements. I mean parent-child relations.
So in our case, the ScrollView returns true when the touch events are a horizontal. The activity's touch event will be handled only if the ScrollView touch event is not handled by itself then you are fine. Otherwise you have to override and implement the on touch event of scroll view and in some cases you have to return false so as for the whole layout to implement it.
The solution is to update Xamarin v2.0.0.6482, which came with my VS 2015 template, to v2.1.0.6529. Updating is a bit of a pain because of this problem https://bugzilla.xamarin.com/show_bug.cgi?id=39721. Once I got that installed scrolling started working with no other changes.
Scrolling is broken in the older version, on Windows, verified by a dev on the Xamarin forums.
I'm using Xamarin Auto Layouts with Storyboard on Visual Studio 2015.
I have a root view, Scroll View and Content View.
I want the application to only scroll on the y-axis but scale on the x-axis.
I want to do something like this.
Adding a view to a scroll view that will stretch to fill available width
Which is setting the width of the content view to the root view.
But using Xamarin this does not seem possible.
So in this example, if I run the application, I have to scroll to the right to see the right most label. I want all three labels to show up on the iPhone, by scaling down on the x-axis.
I have also tried using the "I" handle on the content view in storyboard UI Designer of Xamarin VS, but it doesn't identify the root view.
If it's not possible using storyboard, I will settle with code.
I have tried this.
public override void ViewDidLoad()
{
ContentView.Frame = new CoreGraphics.CGRect(ContentView.Frame.X, ContentView.Frame.Y, View.Frame.Width, ContentView.Frame.Height);
//ScrollView.TranslatesAutoresizingMaskIntoConstraints = false;
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
}
But it doesn't do anything to help me.
How can I scale the UI down on the X-axis while on top of a scroll view using Xamarin.ios?