Making a View scroll once bottom is reached - android

Im trying to create a layout with following looks and behaviour.
<Layout>
<Text "Header"/>
<List> "Contains a couple of texts, most likely LinearLayout" </List>
<Button "Confirm"/>
</Layout>
<Text "Information/Hint"/>
Top-Level Layout is centered on the screen
Information-Text is placed right beneath it (Layout is centered without accounting for this text)
Once the list fills to the point where the Information-Text is pushed out of the screen, the List starts scrolling and the Information-Text remains visible at the bottom of the screen. Distance of the top-border of the top-level-layout to the screen-border is the same as the hight of the information-text
The scrolling-behaviour also takes action if the android-system-settings increased display/text-size to the point where said borders are reached
Its the last two points that give me trouble. I've been experimenting with ConstraintLayout and LinearLayout, but every time the scrolling would work the layout wasn't correct anymore (not centered or margins on the texts screwed)
Any ideas how this could be achived without writing a custom Layout?

Do your view hierarchy like this:
<ScrollView>
<LinearLayout>
<Layout>
<Text "Header"/>
<List> "Contains a couple of texts, most likely LinearLayout" </List>
<Button "Confirm"/>
</Layout>
<Text "Information/Hint"/>
</LinearLayout>
</ScrollView>

Related

Coordinator layout scrolling with unwanted parallax

So we have a 3 part app structure with 2 toolbars: 1 that is significant and should be always visible and 1 that is insignificant and should only be visible when user has scrolled to the top of page .the third part is a complex structure with nested view group, swipe to refresh, recycler view and some extra views . Note that we are not using the Collapsible toolbar or any other toolbar, but rather custom viewgroups.
I tried to achieve the behavior of toolbars with my current xml structure like this (notice the layout behavior flags) (PS: i cannot share the exact code,but would provide more details if needed)
<Coordinator layout>
<include layout=“xyz”> <— <appbarlayout>
<linearlayout :layout_behavior:scroll|enterAlways …/>
<linearlayout :layout_behavior:noscroll …/>
</appbarlayout>
<swipe refresh layout : layout_behavior="....AppBarLayout$ScrollingViewBehavior”>
<Nested ScrollView : mp/mp , fillviewport :true>
<constraint layout : mp/mp>
<RecyclerView : nested scrollin enabled:false (via java code)>
<View>
</constraint layout>
</nested scrollview>
</swipe refresh layout>,
</Coordinator layout>
<!-- mp = match_parent -->
the result looks something like this( gif / video ) (note the gif/video has some delay, please wait 7-8 seconds to see the action ) .
As you can see, the upper toolbar gets hidden when scrolled very hardly, but when scrolled slowly, the upper bar does not hide.
What can i do to fix this? i have tried changing the behavior flags as well as setting the heights as wrap content. I am guessing it is either due to wrong flags or due to complexity in bottom layout

ScrollView for only part of a component? (React Native)

(New to ReactNative)
I currently have a React Native app which has a component with the following (rough) structure :
<View>
<View>
<TextInput />
<Text />
</View>
<View>
<Image />
<Button />
</View>
</View>
So within that parent View, let's call the children View1 and View2. I can very easily substitute the parent View for ScrollView and have the whole component be scrollable. However, what if I want only View2 to be scrollable and View1 to stay in place? And I mean vertical scrolling, not horizontal scrolling/pagination.
How can I do this? Switching out View2 for ScrollView does not work. I'm also looking for solutions where I wouldn't have to split those View1 and View2 into different components because there's a complex mechanism currently in place which relies on sharing state between the two.
Any suggestions? Happy to provide some of the actual code if necessary but I believe the above should be enough to get a feel for it.
Thanks in advance.
This can be solved using a nested component.
As you note, you can very easily have a whole component be scrollable. So by making View2 a separate component, you can implement the scrolling in View2 only.
From http://reactjstutorial.net/
Nested Components Nested Components are exactly what the name implies.
They are children nested inside parent components. They simply help us
create more complex UI structures. For example, an alert component
probably has another sub-component nested within it to indicate the
actual number of alerts. A message box has an inner input element and
a send button.

How to position an Android ListView above a view - without taking up the full space

To allow users to submit comments, I have 2 views, vertically stacked. A ListView for displaying entered comments and a LinearLayout footer, for allowing the user to add a comment (which is basically an EditText and a button).
The footer must be anchored to the foot of the screen and the ListView must sit above it. Its similar to what you see on facebook for Android when you are adding comments.
However I don't want the ListView to initially take up the full space - I want it to take up only the space required to display its rows, but to be able to grow into the remaining space as the user adds comments - while always staying above the footer layout.
I've tried a LinearLayout as suggested here Android: How can you align a button at the bottom and listview above?
However, this results in the ListView taking up all the space above the footer - when there is only a couple of comments - so its mainly empty and looks weird.
I have tried a RelativeLayout parent, where the footer is anchored using android:layout_alignParentBottom="true"..... Positioning the ListView above the footer using android:layout_above="#id/footerLayout" forces the same behaviour as above (ListView takes up all remaining space)... removing this allows the ListView to 'grow' but it overlaps the footer if its grows too big.
Cheers.
I guess this workaround will work!
<LinearLayout
layout_width="MATCH_PARENT"
layout_height="MATCH_PARENT"
orientation="vertical">
<LinearLayout
layout_width="MATCH_PARENT"
layout_height="0"
android:weight="1"
orientation="vertical">
<YOURLIST
layout_width="MATCH_PARENT"
layout_height="wrap_content"
/>
</LinearLayout>
<YOURVIEW
android:layout_width="MATCH_PARENT"
android:layout_height="WRAP_CONTENT"
android:weight="0"/>
</LinearLayout>
I guess one way to do it would be using the android:fillViewport attribute in the XML. See this blog post by Romain Guy: http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/

Android: adding components to RelativeLayout

in My screen, i want to have Hearder(specifically image) on top, and List, and at bottom i want to have small imagebuttons (like youtube,facebook).
I'm using RelativeLayout.. first two are displaying correctly, last one not display at all on the screen, can anyone help here.
my layout file looks like this
<RelativeLayout>
<image></image>
<ListView></ListView>
<RelativeLayout>
<ImageButton></ImageButton>
</RelativeLayout>
</RelativeLayout>
In a RelativeLayout it matters in which order you add the child views (since the latter can be bound to the ones added previously).
I think this is the problem in your layout, you have a fill_parent/match_parent high view already inside (the ListView), and there is no room for the footer.
You should change the order of your views inside the RelativeLayout:
first you should add the header view
(and bind it to the top: android:align_parent_top="true"), then
the footer with buttons (and bind it
to the bottom: android:align_parent_bottom="true"), and
the ListView which should fill up
the empty space will go in as the
thirds view, with
android:layout_below="header_view"
and
adroid:layout_above="footer_view"`
Your layout would then look like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout>
<image android:id="#+id/header"
android:layout_alignParentTop="true"></image>
<RelativeLayout android:id="#+id/footer"
android:layout_alignParentBottom="true">
<ImageButton></ImageButton>
</RelativeLayout>
<ListView
android:layout_below="#id/header"
android:layout_above="#id/footer"></ListView>
</RelativeLayout>

Controlling the scroll bar in my Android application

I have three linear sub layouts in my activity window in my Android application. Each layout has one scroll bar. My problem is when I am trying scroll in one layout area other layouts scroll bars also activating. Could you please suggest a solution for this?
ONE <scrollView> can hold at max ONE component inside it....... this ONE component can be either a layout holding several other views or further layouts inside it, or it can be a single view.
in order to have 3 separate scrolling linear layouts (meaning scrolling one linearLayout does not affect other LinearLayouts)..... you should have 3 separate <ScrollView> elements - each scrollview containing at max ONE of your THREE linearLayout.
for example:
<ScrollView>
<LinearLayout>
all sub-components of **LinearLayout1** goes here
<LinearLayout>
</ScrollView>
<ScrollView>
<LinearLayout>
all sub-components of **LinearLayout2** goes here
<LinearLayout>
</ScrollView>
<ScrollView>
<LinearLayout>
all sub-components of **LinearLayout3** goes here
<LinearLayout>
</ScrollView>
hope it helps you.

Categories

Resources