Android - Problem with ScrollView - android

I have spent a lot of time looking for a solution, but could not find any. I'm almost certain that it will look like a dummy question to some of you, but I'm really stuck here.
I'm trying to have a MapActivity with a 5 rows ListView at the top of the screen, followed by a MapView. The ListView will always be 5 rows big.
I'm using this layout, which gave me the closest of the result I want :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/infoListe"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:cacheColorHint="#00000000"/>
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="wrap_content"
android:layout_height="200dip"
android:enabled="true"
android:clickable="true"
android:apiKey="<KEY_OMITTED_HERE>"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
I get the result I want on recent hi-res devices, but on lower resolution devices, the ListView and the MapView do overlap on the screen.
I would like your help to understand how to add a ScrollView to the layout so that I get a scrollable solution presenting :
1/ the 5 rows ListView
2/ the MapView
If the screen is to small, the user can scroll to get to the MapView section.
Thank you to anyone who will take a few minutes to help me. All my tests have failed so far.
Adam.

Try this workaround : ListView in ScrollView potential workaround
Basically try putting your map into the footerview of the listview to prevent them from overlapping.

Related

Change the view background when an item from a ListView is activated/selected

I'm going to explain (or at least try that) what I want to achieve because this is driving me crazy.
I have a ListView and the items have the following layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/item_background"
android:duplicateParentState="true" >
... some contents here...
</FrameLayout>
</FrameLayout>
"item_background.xml" contains a selector so the background changes depending on the item's state. It's working fine when I press and release the item but it's not working when I 'select' the item with a DPAD/Trackball. I have tried everything (state_activated, state_focused, state_selected...) but nothing works. I'm trying to search for a solution but looks like I can't find the proper keywords to search for.
Any ideas?
Thank you!
Finally I fixed it. The problem was in the order I put the items inside the selector (I put a state_pressed="false" before the state_selected="true").
Now it works flawlessly.
Thank you everyone for your help.
This does most likely not work because some layout above your root layout gets the focus (hard to tell without the rest of the layout).

fill_parent in LinearLayout isn't being honored

After much research on both SO and google, I haven't seen any one with exactly the same problem I am experiencing, so here it is:
I recently redid the entire UI on an android app. For the most part, I made only cosmetic changes to each of the screens. They appear in the UI editor of eclipse perfectly as expected. However, directly after doing this, two of the screens stopped being laid out correctly on both all tested devices and the emulator.
Now, the big problem one these two screens was that the root level LinearLayout didn't appear to be actually honoring the fill_parent for either layout_height or layout_width. it looks like it's being measured as if it were set to wrap_content instead. It only takes up about 70% of the screen - which is just enough to wrap the individual elements inside the root LinearLayout. I would post an image, but as a new user, I am not allowed to.
The layout isn't stretching to fill the screen. Here's the code for layout, except that there are a few more in the LinearLayouts containing a TextView and an EditText.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000"
android:orientation="vertical" >
<TextView
style="#style/sans.white.16.bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:text="#string/edit_account" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.teamunify.ondeck.widget.TUTextView
style="#style/sans.white.14"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/first_name" />
<com.teamunify.ondeck.widget.TUEditText
android:id="#+id/acc_editor_first"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:selectAllOnFocus="true"
android:singleLine="true" />
</LinearLayout>
I think the root LinearLayout should be filling both height and width. I've used this same layout many MANY times in our app without problems. (A quick count revealed that I used 76 LinearLayouts in our app, and all but two of them are working.)
At first, I suspected that perhaps our custom classes measure was wrecking things, so I changed the layout to use all plain EditTexts, but there was no change. I double checked the activity, but it isn't doing anything except to load this xml. So, in desperation, I redid the layout like so:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000"
android:orientation="vertical" >
<TextView
style="#style/sans.white.16.bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center|top"
android:paddingTop="4dp"
android:text="#string/edit_account" />
</LinearLayout>
After that, The words Edit Account appear with a black background mashed into the upper left corner. Clearly, the LinearLayout isn't filling the parent.
Long story short, I am asking how to fix this so that the LinearLayout fills the screen as expected.
I am at a complete loss as to why this is happening, and I am certainly hoping that someone on SO has an idea. This has got me pulling my hair out!
Try setting fixed width and height for the root layout.
Then only you will be able to debug who is driving length and width. It is very much possible that parent activity or background activity is setting dimensions. Once you identify the root cause you can go back to original settings.
As of now from your code snippet given here, nothing wrong here
If you use a custom activity as a container to other activities for some reason (In our case, we were recreating the look of our iOS app, and needed a custom menu to show up along the button side of the screen) the window manager seems to get a bit confused with what the actual height and width of the nested activities should be. A call to fillparent or matchparent ends up wrapping the content instead.
We ended up changing the behavior of several methods in our container activity class to make this work.

How does overlaying views work in Android?

In Android, i noticed that you can have a fixed view on top of another. For example, when you open your browser, and tap the search box, a keyboard prompt pops up (on top of a listview). However, notice that you can still scroll up and down on the listview without the keyboard going away. Like:
would someone please explain (preferrably some sample code in addition) how this works?
What i'm trying to do is just have a custom listview that always has a floating navigation bar on top of the listview and also on the bottom of the list view (it's not actually a header/footer of the listview, it's more like a header/footer of the screen). It would be similar to the example i just described, where the user can interact with both the navigation bar as well as the listview "underneath" the nav bar.
I am somewhat new to Android development, so please be nice and provide a little bit of details if you would :) much thanks in advance!!
whoops. looks like someone had a similar issue:
Layout Layers? Z-Axis?
and this post http://android-developers.blogspot.com/2009/03/android-layout-tricks-3-optimize-by.html explains how FrameLayout works and also how works, which is an even better alternative.
FrameLayout lays object in a different Z-axis, so this is the solution i was looking for.
There are many ways to achieve that, the simpler i can think of is using linear layout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/header">
//Here you add whatever you want in your "header"
</LinearLayout>
//create your listview
<ListView
android:id="#+id/content_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:layout_marginRight="10dip"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip"
android:scrollbars="none"
android:paddingBottom="5dp"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/footer">
//Here you add whatever you want in your "footer"
</LinearLayout>

How to add a fixed LinearLayout below a scrollable ListActivity

what is the easiest way of achieving the following please? I've got a ListActivity which lists a number of search results. The look of the results is an XML specified LinearLayout. The results can go into thousands so I display only a number at a time, say 100. To open next page of results the user needs to click the hardware menu button and click 'Next' from there. I would however like a fixed LinearLayout on the bottom of results with always always visible navigation buttons. How can I do this? Do I somehow nest the XML layouts? Thanks!
You should have something like this:
LinearLayout - vertical, fill_parent in height, and non-scrollable
LinearLayout - vertical, fill_parent in height, scrollable. this will hold the scrolling list
LinearLayout - horizontal, wrap_content in height
Use Something like below. instead of using menu to see next page records. use the last cell of list as view more record button and on click of that add new records and notify the dataset changed.
Search a free app by name starr partners over android market. on the 2nd screen of app you will see a search result list with header and view more records last cell..
Check the code below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:layout_height="45dip" android:layout_alignParentTop="true"
android:background="#333333"
android:id="#+id/linearLayout1" android:layout_width="fill_parent"></LinearLayout>
<LinearLayout android:layout_height="45dip" android:layout_alignParentBottom="true"
android:background="#555555"
android:id="#+id/linearLayout2" android:layout_width="fill_parent"></LinearLayout>
<ListView android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="#+id/linearLayout1"
android:layout_above="#+id/linearLayout2"
android:background="#CCCCCC"
android:id="#+id/listView1"></ListView>
</RelativeLayout>
Hope this help :)

Android scroller paging with page indicator

I am about finishing my first android app, and i have some questions to which i could not find an answer.
I would like to use a horizontal scroller in which to display several pictures. For that i need two things:
Paging enabled, so that the user can see the pictures one by one in the scroller.
Some kind of indicator to show me the index of the picture currently displayed.
If i manage to do the paging, i could probably display a text like 1/4 (2/4 and so on) if i had 4 pictures, but it is not very nice. I would like to have something more like the iPhone has with the gray/white dots. Is there anything like that, or would i have to implement it by adding content at runtime? (adding imageviews according to the number of the pictures and then changing images for them as the user scrolls to show progress)
Thank you.
Because I was already using ViewPager for the swiping UI, I used the excellent ViewPagerIndicator. It took about 5 minutes to integrate.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<include android:id="#+id/titlebar_include" layout="#layout/titlebar"/>
<include layout="#layout/menu"/>
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:id="#+id/product_viewpager"
android:layout_height="0dp"
android:layout_weight="1"
/>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</LinearLayout>
I found the answer i was looking for: i used the Gallery widget and for the indicator dots i used ImageViews and wrote a couple of lines of code to update the selected image dot.
Here is the solution you can try: PageViews and PageIndicator by GreenDroid.
You can also have a look at sample market app: https://market.android.com/details?id=com.cyrilmottier.android.gdcatalog

Categories

Resources