Hi I have a linearlayout and it seems that when I add a second viewflipper that holds two imageviews the second viewflipper is shown on the display screen very tiny. How do I get the linearlayout to allow me to add more views meaning even if I run out of linearlayout space I can just scroll and the linearlayout will show at the normal size.
For example when you go to a website on your phone you can scroll through the website until you reach the end of the page. I would like the same thing to work for my linearlayout.
Scrollview doesn't work/it only works for one child view.
Any ideas?
What is the problem having one child layout? How about this? ScrollView has just one child and doesn't care home many children its child has.
<ScrollView>
<LinearLayout> <!-- parent -->
<LinearLayout></LinearLayout> <!-- child 1 -->
<LinearLayout></LinearLayout> <!-- child 2 -->
<RelativeLayout></RelativeLayout> <!-- child 3 -->
</LinearLayout>
</ScrollView>
Related
I have a fragment containing several layout that I want to move the focus between. The app is operated with a remote containing a D-Pad (up,down,left,right & enter).
Both "view groups" are wrapped in a FrameLayout because the second one i overlapping the first one which is stretching the whole page. The views layout looks like this:
<FrameLayout android:id="contentSurfaceWrapper">
<HorizontalScrollView android:id="contentSurfaceScroll">
<LinearLayout android:id="contentSurface">
<!-- This layout is populated with child layouts (LinearLayout) programmatically -->
<!-- Those layouts are: clickable, focusable & focusableInTouchMode -->
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
<FrameLayout android:id="navButtonsWrapper">
<ScrollView android:id="navButtonsScroll">
<LinearLayout android:id="navButtons">
<!-- This layout is populated with child layouts (LinearLayout) programmatically -->
</LinearLayout>
</ScrollView>
</FrameLayout>
Image of how it looks:
I'm able to navigate to the view: contentSurface and between all its childs with the remote from the action bar in the top of the app. But, now I want to navigate from the first view (contentSurface) and its childs to the second view (navButtons) and its childs. But I doesn't seem to be able to move the focus some how. I want the focus to be moved when reaching bottom in the first layout and back when reaching top in the second layout.
I've tried to make the children in the second layout also clickable, focusable and focusableInTouch but it doesn't seem to work.
So.. I solved it this way:
For the first child in both views, which I append programmatically, I'm setting an ID.
This ID is then used with android:setNextFocusDownId on the items in last row in top layout and in android:setNextFocusUpId on items in bottom layout on first row.
This way I can switch focus in between the childs in both views.
More info about android:setNextFocusUpId etc.
http://developer.android.com/reference/android/view/View.html
I have this structure
<LinearLayout
android:id="#+id/1">
<LinearLayout
android:id="#+id/2" />
<LinearLayout
android:id="#+id/3">
<ListView
android:id="#android:id/list" />
</LinearLayout>
</LinearLayout>
And I populate the ListView with some data. Well my problem is that the ListView becomes scrollable (while the LinearLayout number 1 fits the screen without scrolling), but what I want is this View to become full height and that the LinearLayout with id=1 becomes scrollable.
Inside ListView number 2 I have some TextViews, etc.
ListView's are scrollable by default if when the content is more than its display area.
However, LinearLayout would need to have a ScrollView in order to scroll.
Red Alert - You cannot use ScrollView and ListView together. You will end up seeing un-expected.
Alternate Solution: Prioritize what is more important to you, if scrolling the entire screen then add a ScrollView (provided your ListView items are static) else I will to wait to hear a good solution on this one. :)
Add ScrollView for ListView.
ScrollView will work for only one child view, so you have to add like this
LinearLayout
LinearLayout
LinearLayout
ScrollView
ListView...../ListView
/ScrollView
/LinearLayout
I need to have
ListView - with 3 options
Button
ListView - with 2 options
ListView - with 2 options
as what is displayed on my screen in that order, each underneath and seperate to each other. This will be too large to display on the screen to want a scrollview to encircle it all which people say you should NEVER do.
I dont want my ListViews to be scrollable as I want all the options displayed so how can I do this?
You should never nest scrollable views. Thats right. For your problem replace your ListView with Layouts, there is no reason to use ListViews for what you want to do. The layout should look like this in some way:
<ScrollView>
<LinearLayout>
<!-- your 3 options -->
<!-- your button -->
<!-- your two options -->
<!-- your second two options -->
</LinearLayout>
</ScrollView>
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/
I wanna put image in top of View and a listview bottom of it.
what's best and correct way?
LinearLayout?RelativeLayout?
and with which attribute?
layout_gravity="top"?
layout_alignParentTop="true"?
please give me a snipped code and a brief description about:
what's different between layout_gravity="top" and android:layout_alignParentTop="true"?
I wanna put image in top of View and a listview bottom of it. what's
best and correct way?
If you want to place a ListView below an ImageView positioned at the top of the current view then you could use both layouts, it isn't any real difference.
The layour_gravityis used to place the children relative within its parent bounds(the Relativelayout doesn't have this attribute). For example you could use a LinearLayout with orientation vertical which will stack your two children one on top of the other like you want. Also layout_gravity="top" is ignored for a vertical orientated LinearLayout as it doesn't make sense, so you could remove it from the layout completely:
<LinearLayout android:orientation="vertical">
<!-- the layout_gravity is useless int this case and could be removed-->
<ImageView android:layout_gravity="top"/>
<ListView />
</LinearLayout>
layout_alignParentTop is a placement rule for children of RelativeLayout(only for this type of layout!) which tells them to position aligning the top of the children with the top of the parent RelativeLayout. In this case, to stack the children you would do:
<RelativeLayout>
<!-- you could remove the layout_alignParentTop attribute because by default the Relativelayout will position it's children there -->
<ImageView android:id="#+id/imageId" android:layout_alingParentTop="true" />
<!-- Position this child below the other -->
<ListView android:layout_below="#id/imageId"/>
</RelativeLayout>