I am a beginner in writing applications for Android.
I need an "ImageSwitcher" and populate it with images from a server queue. I've already researched a lot on the internet before coming to ask. Would anyone post some code samples or give some hint on what to search for?
What you're going to want to do it Create a view like this
<?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">
<Gallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageSwitcher
android:id="#+id/image_switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
And then, behind the scenes in some sort of AsyncTask, download the images, and then display them. That code isn't too difficult.
This project on github may be of use as well. It seems to be good for lazy loading images in a listview, but I bet it could easily be modified to load a gallery.
Related
so I want to provide some feedback to the user while I am loading a gridview of images. Below is my adapters UI. I have a very nasty way of doing my task, adding a spinner to each element of the gridview. When the NetworkImageView loads it hides the spinner..
However I ask myself, do I want to use or show this to anyone? No way, aside from being a hack, having 8+ spinners is terrible for performance.
I've been researching it... I see there is some copyNpaste a custom version of the NetworkImageViewer code that lets me put an observer, but that seems to be way intense / overkill.
I also tried putting a callback into the get / set image in the volley ImageLoader to turn off the spinners when the data is accessed. It half worked, but decided it was too ugly of a solution as well.
Aside from just doing it manually with the normal volley request and having to process the image manually and putting it on the volley success listener.. I'm stumped. Anyone know of a clean solution here? I'm guessing I have to do it manually..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="#dimen/image_size"
android:paddingBottom="#dimen/element_spacing"
android:paddingTop="#dimen/element_spacing">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="#dimen/element_spacing"
android:background="#color/color_primary"
android:gravity="center_vertical" />
<ProgressBar
android:id="#+id/grid_adapter_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/gridview_adapter_networkimageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/element_spacing"
android:background="#color/color_primary"
android:layout_centerInParent="true"
/>
</RelativeLayout>
I am developing my first Android app. Although I have 15 years of Java software development experience, Android is new to me. My desired look is a background image with other images on top of it, as well as labels and phone numbers. It seems like the best way to accomplish this is a Linear Layout for the background image, with a nested layout for the other fields on top of that. I have searched online and cannot find any sample code on how to accomplish this. Any recommendations would be greatly appreciated. Thanks in advance.
What are you using to develop? If you are you using Eclipse with the Android SDK this is super easy. Put the desired picture in the appropriate drawable folder, go to the graphical view of layout that corresponds to your activity, on the right side of the screen there is a list of all the properties, find background, then select your picture from drawables. You can also do this from the xml using android:background="#drawable/yourPic". This way you don't have to worry about having things layered on top of it.
I think you should go through followings:
1. http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/
2. http://mobile.tutsplus.com/series/android-user-interface-design/
3. http://coding.smashingmagazine.com/2011/06/30/designing-for-android/
4. http://android-developers.blogspot.in/2011/09/thinking-like-web-designer.html
If I got, something like this can work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
</RelativeLayout>
<stuff>
</RelativeLayout>
I used it in an app, and made the trick.
First of all, RelativeLayout is the best layout to use. It depends on your design.
If your design says to keep all the views either vertically OR horizontally, you can use LinearLayouts in between.
My suggested way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Horizontal">
<View1 />
<View2 />
</LinearLayout>
</LinearLayout android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Vertical"
android:layout_below="#id/layout1">
<View3 />
<View4 />
</LinearLayout>
</RelativeLayout>
Which will yield you something like this
I'm trying to implement something to change between images in ImageView, like a image gallery.
I have this XML to show the ImageView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView
android:id="#+id/hsv_ScrollImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none">
<ImageView
android:id="#+id/id_imgFinal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
</LinearLayout>
My app show images that are in landscape mode, and this is the reason which I am using the HorizontalScrollView. Now I have the problem, I would try to implement something to change to other Image with some kind of gesture, but i don't know if the HorizontalScrollView is a problem for this. Can somebody help me with this? Which method is the most frequently used for this Activities?
Thanks.
Here there is a nice tutorial with a ViewPager. You could even integrate with Gesture-ImageView to add zoom capabilities to the gallery.
Ah! don't forget to add this patch to Gesture-ImageView to better integration.
How about using the Gallery UI widget? It's exactly for scenarios like this. Here's a tutorial for it and the reference.
For my android application I want load image from remote MySQL database to the Gallery View using JSON.
Is it possible or not.
possible means any one help me with some sample code based on this
This is possible. First of all you need to get the image url saved in the remote server. That can be made possible by an api call either by using JSON or any other mode. By that api you can retrieve the image url's saved on the remote database. After getting all the image url's you can load the images using Lazy load of images in ListView. On the LazyLoading code they have used a ListView in the layout so the images and the corresponding text are shown as list items, you can change that ListView to a Gallery something like this:
<?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">
<Gallery android:id="#+id/gallery" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Clear Cache"/>
</LinearLayout>
I think this will get you the desired result.
For some reason, whenever I scroll through my list of items, the background inside my listview disappears and reappears giving rise to a "flicker" effect which I don't really want. I've tried the suggestion at: How to make a ListView transparent in Android? but it doesn't work for some reason. Any suggestions?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/screenLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/title_background"
android:text="#string/whatsnew_title"
>
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
Did you include android:cacheColorHint="#00000000"? It's the most important part of the proposed fix. I've just tried your code (obviously not an exact reproduction, as you're using references to project-specific resources) with it, and it seems to work.
This post on the Android Developers blog should be of your interest.
This can also be achieved from Java (code) side: listView.setCacheColorHint(Color.TRANSPARENT);
Check your theme.xml for <item name="android:windowBackground">#null</item>. If you have it - remove it. I think one of the popular resources gives this line as example (that's how I got mine).