Pick value by swiping image on horizontal bar - android

I want below mentioned functionality in my app but don't know which widget i should use.
As like above image, user can slide image/view on horizontal bar to pick value, user can pick any value between 0 and 720, There is milestone at every 30 points
Now the main point is as soon as user swipe image to right most on horizontal line, Line must scroll towards left and must change milestones accordingly (Like 90,120,150.....720) so basically its horizontal value picker and user can slide it to pick desired number.
Also user can swipe right to left to select previous values. values are fixed 0 to 720

Try this !! https://github.com/AnderWeb/discreteSeekBar
and try to change the thumb to drawable
Drawable myThumb = getResources().getDrawable(R.drawable.slider_button);
myThumb.setBounds(new Rect(0, 0, myThumb.getIntrinsicWidth(),myThumb.getIntrinsicHeight()));
skbr.setThumb(myThumb);
How can I change the Android SeekBar Thumb drawable after 'onCreate' method?

Related

Hi.I am new to android, and I want to achieve below image slide view In which next and preview image should appear a bit

I am new to android, and I want to achieve below image slide view in which next and preview image should appear a bit. I am using App-intro library. I have stored images in local . I tried with App-intro library but I'm unable to achieve the result. Thanks in Advance.Image slide with next and previous image preview(a bit)
Try below solution to achieve what you want.
viewPager.setClipToPadding(false);
// set padding manually, the more you set the padding the more you see of prev & next page
viewPager.setPadding(40, 0, 40, 0);
// sets a margin b/w individual pages to ensure that there is a gap b/w them
viewPager.setPageMargin(20);
Whatever padding you want on top and bottom specify in xml file
android:paddingTop="30dp"
android:paddingBottom="50dp"

Move button back to origin after dragging/moving it

I have an ImageButton that I need aligned to the bottom of the screen, and when I click and drag it, it moves with my finger by a certain distance, beyond which it will not move further from the origin but continue following the direction my finger is from the origin.
When I let go, the button has to slide back to the origin.
What I have managed to do so far is to have the button follow my finger via this answer: Moving buttons via Touch
However, how should I get the origin of the button at initialization for it to bounce back after I release?
Originally I implemented the alignment of the button by having a android:layout_gravity="center|bottom" to place it at the bottom, but it somehow messes with the position of the button relative to my finger (It follows my finger movements but it's off center).
Hence, I used mButton.setY() and mButton.setX() to place it at the bottom of the screen, but it seemed hackish to use the screen dimensions to place it. Can't think of a better way.
You can set the width and height of your layout in XML using
layout_width and layout_height.
Then in your MainActivity, instantiate the layout (I will use LinearLayout as an example) and get its width and height.
LinearLayout l = (LinearLayout)findviewbyid(R.id.l1);
int height = l.getHeight();
int width = l.getWidth();
Now, whenever you release the button, you can set your its position in the following way:
mButton.setY(height - 50)
This will position the ImageButton 50 pixels above the bottom of your layout. You can also set the x position of the button as you want in the same way. Also, you should probably store height - 50 as a global variable (origin) that you can call from anywhere in your code.

Custom viewpager imageslider?

Although This is a solution ViewPager with previous and next page boundaries but it has limited scroll to only visible current image and does not work when i try to scroll from extreme left or right.
I want side images from left and right to be a little smaller and centre image to be on focus and larger like the image shown and with the indicator and text.
Not sure that got you right, but something similar I've done with:
pager.setClipToPadding(false);
pager.setPadding(50, 0, 50, 0);
UPD.
ViewPager indicator
In order to scale not visible fragments, try to use setOnPageChangeListener, and scale position - 1 and position + 1 fragment's view. Here how to take reference on fragment from ViewPager.

Place an imageview on customdialog screen depending on variable

I'm trying to place a small image on the top of a big one in a custom dialog.
I want the small one to be placed in a different place depending on a variable, which I called "pos". It contains a int value from 0 to 100, meaning percentage of the dialog width.
If pos = 0, I want to place the image in the left margin of the big one, if pos = 30 it should be placed in the 30% of the screen, starting from the left.
If pos = 50 I want it to able placed right in the middle, being 100 the maximum value for it and placing it in the right margin.
I include a draft to explain myself a bit better.
I tried with RelativeLayout.LayoutParams but I never get expected output.
Perhaps a simpler strategy is to extend ImageView, then create a custom image using Canvas commands in the onDraw method that draw the bitmap appropriately on the x axis with a background set to match your layout.
You can determine the width of the custom dialog in the the onMeasure method of your custom ImageView, so the returned bitmap (including empty background) can be the correct width, and the position of the smaller bitmap can be correctly apportioned.
Once you've created the class, which will take just a few minutes, you can add it to your XML layout with something like:
<com.domain.yourapp.YourCustomerImageView
android:id="#+id/bitmap_graph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"/>

Image(s) placement over a image in Android

I was attempting to place a image on top of another existing image in android. Here was the game plan. First the user would select a button and then that button would tell the program to populate a sprite/ image to a fixed location on the master Image. Once the image is set the user could then hit a button for another image on top of what is currently their, (the goal is two images with a option to change their size, x and y position. I am only using android 2.1 platform! The button for selection and the text describing the activity are in a linearlayout.
You should use a RelativeLayout and then you can use params to set position, margin, etc..
something like this:
//this is your fist item
r1.setImageResource(R.drawable.myimage);
//this is the second item
r2.setImageResource(R.drawable.myimage2);
RelativeLayout.LayoutParams imageParams=
new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageParams.setMargins(1, 1, 1, 1);
imageParams.addRule(RelativeLayout.BELOW,r1.getId());
addView(r2,imageParams);

Categories

Resources