Android SeekBar Doesn't Move Smoothly - android

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

Related

CircleIndicator does not fit the screen

I am using this library https://github.com/ongakuer/CircleIndicator, in some cases too much data is coming. The indicator goes out of the screen, can I add animation to it, there is an animation that exists as default in ios.
Ios Example: https://streamable.com/6nu6j3
Android Problem:
I found this as a problem like this before, i was wondering if there could be a nicer solution like in ios
How to set a limit of items on CirclePageIndicator?
Layout
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewPager2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<me.relex.circleindicator.CircleIndicator3
android:id="#+id/circleIndicator"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="#id/viewPager2"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:layout_marginRight="25dp"
android:gravity="center"
app:ci_drawable="#drawable/circle"
app:ci_height="5dp"
app:ci_width="5dp" />
Edit:
This library my work has been read -> https://github.com/wching/Android-Indefinite-Pager-Indicator
you have to set margin into your root level layout according to that they set margin .....
and don't check into the emulator some time emulator may be goes wrong so check it into real device only

Volley NetworkImageView with spinner?

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>

How to make background larger then screen and rotate it?

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.

Android: Buttons swapping place at runtime in horizontal, weighted LinearLayout?

I'm using a horizontal LinearLayout to divide a rectangular block of the device's screen into 3 equal parts. This is accomplished using weights.
The purpose of this is putting 3 buttons side by side, a settings button, a help button, and a contact button. As per my knowledge, it should follow that the first button in the LinearLayout is on the left, the next is in the middle, and the last is on the right, due to the hierarchy rules of a LinearLayout.
This is what the Visual Editor also shows. But when I run the application (and I've tried on multiple devices), the contact button ends up on the left, the settings button ends up in the middle, and the help button ends up on the right.
I tried changing the hierarchical structure of the code (i.e. I placed the code for contact button above the code for settings button, etc.) but it didn't make any difference to the result.
The code for the LinearLayout is below:
<LinearLayout
android:id="#+id/icons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100">
<ImageButton
android:id="#+id/settings"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:src="#drawable/settings" />
<ImageButton
android:id="#+id/help"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:src="#drawable/help" />
<ImageButton
android:id="#+id/contact"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="33"
android:src="#drawable/contact" />
</LinearLayout>
There is nothing wrong in the XML. If the application is really using the above XML, then changing the ordering of the ImageButtons in the layout should indeed change the ordering on the screen.
Here's 2 things that come to mind:
There is a problem with your build/run process, and updated code changes are not reflect when you run your application. I suggest making a change to some obvious string resource and test if this is the problem. You should also do a clean build just in case.
You have multiple layout files with the same name (for example, one in layout/ and the other in layout-land/), and you're not changing the right one.

Android GUI: what are the good UI patterns for entering an integer number?

There are two numbers constantly displayed in my UI. I need the user to be able to specify those numbers. In a desktop app I simply use 2 spinbuttons, and can beat it (I guess). However, there are problems with this in Android (I am targeting Android 3-based tablets).
First of all, I've tried NumberPicker widget, but it simply does not show itself properly (I've asked a question about it, but no response so far).
Then I've tried some 3rd-party numberpicker implementations one cand find on the Web, but for various reason didn't like neither of them. Some of them are too large to fit the side panel I'm squeezing controls into, some are just ugly (and too small, probably), and all of them automatically grab input focus causing the keyboard to show every time I open this side panel.
There is another option - only show the uneditable label with a number on the panel, and show popup window with some numberpickers in it. Apart from me not knowing how to implement such a popup (just learning), how do I decorate the label so that the user understands he can tap it to edit?
Perhaps, there are better solutions for this problem? I took a look at some apps from Google Market, and they all seem to either use huge NumberPickers at the center of the screen (and I need as much of the screen as possible clear), or a popup with the same huge Numberpickers I don't particularly like.
Can you suggest anything else? Thanks in advance!
There are two different issues in your question:
For the number picker for eaxmple in my case I have created a simple tool. You can just put a button with the text "-" then a textview and then a button with "+". You put it in a linear layout and t can be vertical or horizontal. If you want it you can make it very small. For example here is what I have wrote but you can try playing with the options to see which is better for you.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical" android:id="#+id/linearLayout1"
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content">
<Button android:id="#+id/button22" android:layout_gravity="center"
android:layout_weight="1" android:text="+" android:gravity="center"
android:layout_width="30dip" android:layout_height="30dip"></Button>
<Button android:id="#+id/button11"
android:layout_gravity="center"
android:layout_weight="1" android:text="-"
android:gravity="center" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_height="30dip" android:layout_width="30dip"></Button>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1" android:orientation="vertical">
<Button android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="30dip"
android:text="0" android:id="#+id/quantidad"></Button>
</LinearLayout>
then you can add onClick listeners on the buttons and setup to increase or decrase the text displayed in the text view.
As for the keyboard well if you use that example you not need it but if you use an edittext then you can setup an option for the keyboard to be hidden in the manifest: you can see the option here http://developer.android.com/guide/topics/manifest/activity-element.html

Categories

Resources