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>
Related
I'm trying to write a Camera app in android. I wanted to use a SeekBar for zoom in/zoom out of the camera. Here goes my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<SeekBar android:id="#+id/sliderZoom"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
/>
</LinearLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:background="#000000">
<ImageButton
android:layout_height="50dp"
android:layout_width="wrap_content"
android:src="#drawable/flash"
android:scaleType="fitXY"
android:layout_alignParentTop="true"
android:onClick="onFlashClick" />
<ImageButton
android:layout_height="50dp"
android:layout_width="wrap_content"
android:src="#drawable/zoom"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:onClick="onZoomClick" />
</RelativeLayout>
</LinearLayout>
If I remove either of the ImageButton, my SeekBar moves smoothly. But it doesn't move smoothly if I've both of the ImageButton. I tried to run the app both in portrait and landscape mode. The problem remains same in both mode.
How can I solve it?
EDIT: As per some comment, I feel to add some more information. Right now there is no event handler for the SeekBar. It doesn't zoom in or zoom out the camera. It is just one simple SeekBar' with maximum value set to some random integer. For my case I tried 5 to 500. In every case I've the problem. By smooth move I mean when I try to slide it with touch it should move easily, should not halt. If there is one ImageButton, I can slide the SeekBar pointer left/right without any problem. But if there are two ImageButton, the pointer doesn't move that easily. It looks like each time the the pointer is moved by one unit, some time consuming operation runs on the UI thread which halts the UI from capturing touch event. Though the fact is there is no time consuming operation in UI thread. There is not a single function written for any type of computation. I didn't even add the camera preview in the FrameLayout or camera isn't initialized
More Edit: I just found out one interesting turn of event. If the image source is same image(doesn't matter which one) for both ImageButton, then it works perfectly. But if I've two different image for two ImageButton, then it starts causing the problem. I hope this new information will help to get some idea of what is happening. The resolution of the images are 1299x1299 and less than 40kb in size.
Actually this is not a problem. Camera zoom level is not so much. Basically zoom level is 5-7. So, as you have used SeekBar as your zoom controller it means your seekbar's max level is 7(suppoose). For this reason, it buffer per level when you pull the bar.
For your test, you can set value seekBar.setMax(30) and then pull your seekbar. I hope you will get that smooth
Want to make space background to my activity and begin to rotate it slowly, but i stuck with that:
screenshot (http://postimg.org/)
The effect I need need I can get if add in XML file
android:scaleY="2"
android:scaleX="2"
but it will not work, android scale pic down when app start.
Guys, really need your help, I in android for 4 day and have bad english
----ADDED---
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/backgroundd"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
I have not tried this, and I am not sure it is the best solution, but could you set a negative android:layout_marginon the image?
android:layout_margin="-100dp"
See here for more: How to get a view larger than its parent?
Also, posting your full XML could help us know more about how you are setting up the layout.
I have 2-3 Activities in my app that all share data in a memory pool. I want to be able to easily switch between these activities while keeping them all simultaneously running. In addition, I am developing for Android 4.0. I would like to use TabActivity, but it has been deprecated and replaced with ActionBar, which I have tried but I don't think it's what I'm looking for. I want large tabs, similar to the classic "Artist/Playlist/All" tabs found in the stock Android Music Application, or like the Tab Bar seen at the bottom of the screenshot below. Does anyone know of a library to create these tabs or a way to make ActionBar more customizable? Or is using TabActivity a perfectly good solution, even on ICS devices?
ActionBar is what you're looking for, actually.
You should convert your Activites to Fragments. Assuming they're not too complex, this shouldn't be hard at all. There are tons of examples out there. You need one Activity, preferably a FragmentActivity, to hold all of them.
This should help:
http://arvid-g.de/12/android-4-actionbar-with-tabs-example
There are several subquestions to this, I'll try to address them all:
-In order to use the top tabs, you want to use an ActionBar.
-If you were to do it in the style of the music app, where you swipe sideways between views and the label of the current one is always front and center... For that, the class you'd want to use is called ViewPager
You can see all of these methods by creating a new Activity in eclipse, and going through the wizard. Under "Navigation Type" you can select "Tabs", "Tabs + Swipe", "Swipe Views + Title Strip". Create any one of those Activities to see how it looks, and then look at the code to see how it's implemented & how to customize it.
-Navigation along the bottom is discouraged- See the Android Design Guide, spec the section "Don't use Bottom Tab Bars"
You have probably found an answer by now, but I thought I'll share another way you could create something like that tab bar using images and xml:
<?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="fill_parent"
android:orientation="vertical"
android:id="#+id/main">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/tabackground"
android:layout_alignParentBottom="true"
android:id="#+id/llBottom">
<ImageButton
android:src="#drawable/icon2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
<ImageButton
android:src="#drawable/icon3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
<ImageButton
android:src="#drawable/icon4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
<ImageButton
android:src="#drawable/icon5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
</LinearLayout>
<ImageView
android:layout_height="24dp"
android:layout_width="fill_parent"
android:layout_alignTop="#+id/llBottom"
android:background="#10ffffff"/>
<ImageView
android:layout_height="1dp"
android:layout_width="fill_parent"
android:layout_alignTop="#+id/llBottom"
android:background="#30ffffff"/>
</RelativeLayout>
Is not perfect but with some creativity and changing some values it can look very good.
Hope it helps in some way.
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.
I have in my application a listview with an adapter that uses different layouts for the items.
I want the result to be like in the attached exp_result.png.
http://imageshack.us/photo/my-images/717/expresult.png/
But unfortunatly - I get like in result.png.
http://imageshack.us/photo/my-images/839/resultf.png/
The problem is that image stretches on the screen not the way I wanted.
Any ideas?
Maybe other solution to this layout - maybe built in?
Drawables are in the links, since I cannot upload images. The original picture is like in the first listview item in the exp_result.png. I want to use 1 picture for each - top, buttom and middle and to be used no matter the listview item size. XML is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_up" >
<TextView
android:id="#+id/name_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
<TextView
android:id="#+id/number_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="28dip" />
</LinearLayout>
I can really really use some help here.
Yoav
This may be a good application of the 9-patch image type:
9-Patch