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
Related
I'm trying to make AppWidget shows rotation images which can automatically change every 5 seconds,and I think ViewFlipper might be able to reach this goal.
But I get images from server and can't just put them as ImageView in .xml file under nested ViewFlipper like this:
<ViewFlipper android:id="#+id/viewflipper"
android:layout_width="match_parent"
android:layout_height="match_content"
android:autostart="true"
android:flipinterval="5000" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/drawable1"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/drawable2"/>
</ViewFlipper>
I need to add images dynamically, and shows one picture at one time. If there's more than one image, they need to be shown on AppWidget by turns.
Hope somebody could help me with this, thanks!
I assume by "dynamically" you mean there could be an arbitrary number of items. What you probably want is AdapterViewFlipper. You can follow this guide for building an AppWidget whose content is backed by an adapter.
I'm now facing quite interesting problem in develpoing android app.
So, I have 3 sections, and the order is following.
[VIEW_ON_TOP]
[TO_BE_STICKED]
[SCROLLVIEW]
Of course, scroll view has many children views, anyway it might not seem to be the problem.
What I'm trying to do is that when I scroll the [VIEW_ON_TOP] until the top of the [TO_BE_STICKED] is on the top of the screen, the [TO_BE_STICKED] section should be sticked on the top literally, then I have to move on the focus on [SCROLLVIEW] for scrolling, which means that there are exactly two sections for scrolling.
Thus, what I'm thinking is that let these 3 sections be included in the one listview, so each section is one of the listitems, then it would be nothing but the problem for 2 listitems and one sticky header problem of listview. How do you think? Is it resonable idea? Or any other suggestions, or comments?
Please note that [VIEW_ON_TOP] and [SCROLLVIEW] is independent xml file, so it is needed to make these into object for listviewitem.
I found a simple library on GitHub.
https://github.com/emilsjolander/StickyScrollViewItems
the procedure is following.
<com.emilsjolander.components.StickyScrollViewItems.StickyScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/sticky_scroll">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:weightSum="5">
<include
layout="ON_TOP"
/>
<View
THIS IS FOR SEPARATE LINE
/>
<include
layout="ON_BOTTOM"
/>
</LinearLayout>
</com.emilsjolander.components.StickyScrollViewItems.StickyScrollView>
tl;dr: What do I need to do to get the result from the first image instead of the second one (concerning the blue squares)?
First, the code snippets are at https://gist.github.com/exhuma/125ec8a5e32b395fd786
and an image for reference, representing the intended outcome:
I have an application with 3 RecyclerViews. One "main" list in the center, and two "status views" to the left and right of it. The main list works as intended, and it should be scrollable. The ones to the left and right have cards which will rarely (if ever) fill the whole screen height. Scrolling would be a nice-to-have, but is not necessary. They both represent sort of a "pending queue" of items which will soon appear in the main list, visualised with small icons.
I tried just going about the business in the same way as I did for the central view. But when I did that, it resulted in the cards in the "queue" lists to be evenly spaced like this:
My question is: What LayoutManager does this? Or should I use something else than the RecyclerView instead? Like a ListView?
The solution is to force the cards of the RecyclerView to a fixed size. Replace this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#id/statusIcon"
android:maxHeight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
With this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#id/statusIcon"
android:layout_width="20dp"
android:layout_height="20dp" />
</LinearLayout>
Obviously, this will not scale with screen sizes. There still might be a better solution. This works for now...
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>
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.