Android Developer has a nice discussion on writing your own View subclasses:
http://developer.android.com/guide/topics/ui/custom-components.html
But I want to write my own ViewGroup subclass with my own child positioning policy. Where is there a minimal example of this kind of thing? (This is a Java coding question not an XML one)
Specifically I want a horizontal layout that (like LinearLayout) fills in children from the left - but once the horizontal space is consumed, shifts the children to the left so that the last child appears aligned to the right end of the layout. The children are button-like and so a HorzontalScrollView does not work since the scrolling gesture clicks the buttons instead of moving them.
If LinearLayout has an option to do this, I could not find it.
HorizontalScrollView should work, scrolling should not click the buttons. But if you really want to write your own custom layout, have a look at this archive (the video is also available)
Related
I'd like to be able to scroll through my main, outer layout vertically even if my thumb (touch) is within a horizontal scrollbox (which allows me only to scroll through its items horizontally). I've already tried replacing the horizontal scrollbox with a standard TScrollBox but without luck.
Examples of this can be found in applications such as Instagram (with their stories) and Facebook. A concept image is shown below from another question whose answer isn't applicable in Delphi.
Edit: there's a component in Android called 'Nested Recycler View' that does this exact thing I'm looking for. Is there anything similar for Delphi Firemonkey?
have you tried awsome controls from https://github.com/Zeus64/alcinoe
try to build single row of main layout with tabs and slide efect
How does Android think about ScrollViews?
I come from webdev background, so that is my paradigm for implementing a scrolling element.
Yet on Android, official tutorials and docs say, I should use height="wrap_content" for the ScrollView. But why?
From my understanding(webdev), ScrollView should be the container, in which it's content scrolls. Meaning ScrollView being the height restriction (therefore match_parent) and it's content should be higher than that (therefore scrolling).
If I set ScrollView height to wrap_content, and Android would actually honor that... it should not be scrollable (by my webdev paradigm) (unless Android does not add additional layout containers (outside those defined in layout file).
So how is it done?
A view group that allows the view hierarchy placed within it to be scrolled. Scroll view may have only one direct child placed within it. To add multiple views within the scroll view, make the direct child you add a view group, for example LinearLayout, and place additional views within that LinearLayout.
Here is a Link that helps you to know more about it
https://developer.android.com/reference/android/widget/ScrollView
and also here
https://www.javatpoint.com/android-scrollview-vertical
I want to develop an app that includes GridView and I want it to be some thing like horizontal ListView above a gridvew .Horizontal view displays images downloaded from url.I saw this touturial ( horizontal scrollview used)
and saw this to put the GridView inside scrollView because i want to put the gridview(episode #2) and horizontal view (episode #1) in vertical scrollview(episode #3) . I need to scroll the horizontal view vertically when a user is scrolling the gridview and not to have fixed position at the top of the screen.
I have no idea how to do this (use horizontal ScrollView or horizontal Listview)?
after vertical scrolling I want it to be like this (horizontal view must get scrolled vertically):
This is a custom interaction, so you probably will not be able to use a "standard" tool for this. You may want something like the FloatingActionButton (an example here: http://antonioleiva.com/collapsing-toolbar-layout/) but you also want it to scroll, so you may need to extend that class.
Also, you could use touch events to do a custom animation on the area, because you will need to track when it is displayed and the direction/distance of the motion event to collapse/expand it. You also would need to know anchors on the list, to determine when it should reappear...
This is a cool design concept, but usually "cool" = "difficult" because it's not standard.
I'm developing an app that has an UI pretty similar to Play Store. It is organized as a multiple panels one above another. First it has a panel containing a photo. Under that it has another panel containing some text and a custom background color. Under that it has another photo and finally it has a Linear Layout with vertical orientation containing a pretty long list of little views filled dynamically at runtime. I have all this inside a Scroll View, naturally.
The problem? That dynamic fill of the linear layout takes a long processor time and makes my app unresponsive during those inner views inflation. So I thought to replace the linear layout by a Recycler View. And the performance is awesome!
So? Well... Not everything is so awesome. I can't scroll the Recycler View because it's inside the Scroll View. And if I remove the Scroll View then I can't scroll the entire view (some things doesn't fit on the screen).
What's the best approach for fixing this?
It's not recommended to use a RecyclerView or ListView inside of a ScrollView precisely due to the double scrolling issues. RecyclerView is very robust and is prepared to receive headers, footers, etc. I see no reason why the entire layout could not be inside of a RecyclerView instead of a ScrollView
The ViewHolder implementation can include logic to inflate different layouts depending on what section should be next.
Pseudocode:
i.e.
if(currentAdapterItem == sectionA){
useLayoutA();
} else{
useLayoutB();
}
Just use a NestedScrollView instead of a normal ScrollView. It handles the nested scrolling quite well.
I am trying to build the following layout, but am unsure which android layout I should be using.
Its just a table (correct terminology?), but I would like functionality such as swipe to delete a row, and to expand on click (to reveal another view). It should also be scrollable.
What I have currently is a LinearLayout on a scroll view, which I populate with other custom layouts.
To achieve the expanding functionality, I have more custom views in the LinearLayout which are hidden by default, and then revealed if they layout above them is pressed. All of this lives in a ScrollView.
Would a TableLayout be better for all of this? I originally picked LinearLayout instead of TableLayout because I was confused about the TableLayout columns (and didn't need multiple columns). I feel like right now I am reinventing the wheel.
You don't need ScrollView or TableLayout at all. The easy way is to use a ListView, then on the raw adapter, you implement an onTouchListener method with swipe gesture algorithme (not hard to code).
But the swipe and expandable view can be handle with this library (very usefull)
https://github.com/nhaarman/ListViewAnimations