How to create a slider on an image - android

This is what I am trying to achieve
The black rectangle is an image asset which i need to move left and right on related touch events/drags
Being relatively new to Android , I am finding this difficult to implement.
So was hoping I could get some tips,guides,examples if there are any.
EDIT:
I Have tried viewflipper but that is not what I need here,
I tried making a slider like a seek bar , but didn't work out.
Some one suggested that I use a framelayout over the main image to slide but I don't know how to do it.
So any help which will help me out here is appreciated

Use SeekBar because it suits your needs completely.
First create a drawable xml file named "rect_border.xml" in res/drawable folder with these contents:
// **EDITED**
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:color="#000000"
android:width="5dp"
/>
// change the width to any value that suits your needs.
// set the height property greater than your image height
<size android:width="50dp" android:height="360px" />
</shape>
Then in your layout:
// **EDITED**
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="300px"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="#drawable/your_image"
/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="#drawable/rect_border"
android:progressDrawable="#android:color/transparent"
/>
</RelativeLayout>
I tested it and I'm sure it's actually what you want (as described).
So what's the problem about the SeekBar?

Related

Android : Rounded-edges view grow within another rounded-edges view

I am trying to make two rounded edges views, A and B, in Android. Both views have the same corner radius but B is within A or B should look like within A.
B's width is dynamic according to the percentage below. When the percentage is more than 5%, this works perfectly fine. However, as the percentage is less than 5%, it will turn out like the failure-figure below. They look like completely independence views, though they actually are. I need the green part grows within the gray area only. How can this be accomplished?
Ideally, it should look like
But I failed to make it. :/ The figure I got
Here is what I did, define a drawable as given below
<RelativeLayout
android:id="#+id/percentageBarViewGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/a_Bar"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#drawable/progress_bar_empty_background"/>
<View
android:id="#+id/b_Bar"
android:layout_width="0dp"
android:layout_height="20dp"
android:background="#drawable/progress_bar_progressing_background"/>
</RelativeLayout>
You should use nested views and padding .
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<FrameLayout
android:id="#+id/a_Bar"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#drawable/progress_bar_empty_background">
<View
android:id="#+id/b_Bar"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#drawable/progress_bar_progressing_background"/>
</FrameLayout>
</RelativeLayout>
At the end add stroke to your progress_bar_progressing_backgroundwith the same color as progress_bar_empty_background.
something like this :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="3dp"/>
<stroke android:width="2dp" android:color="#222"/>
<solid android:color="#fff"/>
</shape>

Custom RelativeLayout to have circular boundary

I have a requirement to show a View which need to have a circular boundary.
I know it can be done by Extending the RelativeLayout. But exactly dont know what all methods to override except constructors and what code changes I have to make for it to show circular boundary.
Updated question with Image.
So basically this is an animation.
and minutely the view goes out from screen from the circumference of the circle (And not as rectangular view).
So I have to create a circular view (Relative Layout) that is having child of these images.
Use android.support.v7.cardview and put a RelativeLayout as its child.
https://developer.android.com/reference/android/support/v7/widget/CardView.html
Note from the above link:
Due to expensive nature of rounded corner clipping, on platforms
before L, CardView does not clip its children that intersect with
rounded corners. Instead, it adds padding to avoid such intersection
(See setPreventCornerOverlap(boolean) to change this behavior).
i think you need to make any layout with rounded border. using below code for make layout rounded.
round.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><shape>
<solid android:color="#color/list_row_bg" />
<corners android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp" />
<stroke android:width="1dp" android:color="#color/header_bg" />
</shape></item>
</selector>
put this round.xml file drawable folder. and use as backgournd in your layout.
my_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="25dp" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round" />
</LinearLayout>

Background in a layout not appearing unless I put something in the layout

I'm trying to draw a box around two TextView objects in Android. Prior to this I had the two TextViews in a LinearLayout, but I'm working on flattening my view hierarchy to improve performance. When they were in the LinearLayout, the background showed up as desired, but when I create an empty layout with the same dimensions, I don't see the background show up at all.
My guess is this is because there isn't anything in the FrameLayout (I also tried an empty LinearLayout). I also tried setting this value at run-time, but same result.
This works fine in the layout editor in Eclipse, but when running on my tablet, the background just isn't there.
Any suggestions to accomplish the same thing or any suggestions for what I'm missing would help. Here's the shape:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#508E8F8E" />
<stroke
android:width="1dip"
android:color="#8E8F8E" />
<corners android:radius="4dp" />
</shape>
And here's the layout:
<FrameLayout
android:id="#+id/box_around_text"
android:layout_width="35dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#drawable/background_gray"/>
<TextView
android:id="#+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="first_text" />
<TextView
android:id="#+id/second_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/first_text"
android:text="second_text" />
The issue was that the shape must have real dimensions defined somewhere. I can make it show up if I define a size in the shape itself or if I use numbered dimensions in the layout. It would never show up if I used the 'wrap_content' or 'match_parent' options.

how to create rounded corner videoview in android?

In my application, I want to display videoview as a rounded corners. I have tried placing videoview/surfaceview inside linearlayout with rounded corner set to linearlayout. but it does not work perfectly. I can not set rounded corner to videoview/surfaceview. I want to set view as below image:
Anyone have idea how to do this?
Not sure why there are so many bad answers when the solution is really simple (as long as you're min sdk > 21). Creating a shape and putting it overtop of the video won't work because you obviously want the background to be transparent to see the views behind it.
I found the answer here Android View Clipping. You just put the video view in a frame layout, add a rounded background to the frame layout, add an outline provider and clip the frame layout to the outline.
The background rounded_video_background:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#000000"/>
<corners android:radius="16dp" />
</shape>
The frame layout and video view inside of it:
<FrameLayout
android:id="#+id/video_view_container"
android:layout_width="90dp"
android:layout_height="120dp"
android:background="#drawable/rounded_video_background"
android:outlineProvider="background">
<VideoView
android:id="#+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
</FrameLayout>
And the final step is clipping to the outline (didn't see a way to do it in xml so I did it programatically):
video_view_container.clipToOutline = true
Its worked for me,
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
android:layout_width="match_parent"
card_view:cardCornerRadius="25dp"
android:layout_height="wrap_content">
<VideoView
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="215dp" />
</android.support.v7.widget.CardView>
You can make it using a FramLayout & an XML drawable
FramLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<VideoView
android:layout_width="match_parent"
android:layout_height="#dimen/dp_240"
android:layout_margin="#dimen/dp_24"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rounded_corner_video_bg" />
</FrameLayout>
XML Drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="#dimen/dp_24"
android:color="#color/md_white_1000" />
<corners android:radius="#dimen/dp_24" />
</shape>
You could try layering different views on top of each other to create the rounded corners you are looking for. Try placing four ImageViews over the VideoView in each corner, to achieve the desired rounded corners. I have had success using a RelativeLayout to accomplish this, but you could also try using a FrameLayout to hold the Views together.
It is directly not possible, but you can do this by draw a imageview on top of videoview and set an image having transparent from between and solid color in rounded shape on the corners.
check this: Click here
Its simple,
1. Create a drawable with rounded corners as mentioned by #sunil kumar
2. Set that drawable to your layout as a background
3. When using that layout set layout(your layout item name).clipToOutline = true
This is XML code of rounded VideoView.
<androidx.cardview.widget.CardView
android:id="#+id/videoCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="20dp"
card_view:cardBackgroundColor="#color/white">
<VideoView
android:id="#+id/relativeVideo"
android:layout_width="match_parent"
android:layout_height="225dp"
android:paddingTop="-10dp"
android:paddingBottom="-10dp" />
</androidx.cardview.widget.CardView>
Negative padding is important otherwise height of VideoView is smaller than cardview by half of cornerRadius in both top and bottom side. You can set height whatever you want but negative padding should be half of cardCornerRadius all the time. Purple in the image is a video preview, not related to xml.
Have a nice day!
put rounded.xml in your drawable folder and set on framelayout of video like android:background="#drawable/rounded.xml"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFFFF" />
<corners android:radius="7dp" />
</shape>
Create an xml file in drawable folder called shape_video.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="6dp" />
</shape>
Change the radius according to your rqmnt and in the background attribute of your videoview, give
android:background="#drawable/shape_video"

Android - Change seekbar bar size

I'm playing a bit with Android developing some sample applications and came across issue I can't get over with. I'd like to change width of "bar" of SeekBar view.
What I want could be better seen on screenshot provided
http://i.stack.imgur.com/XczAf.png
Could some please be so kind and help me out?
Thanks a lot in advance
You can use thumb drawable for to change hight and and thumb image
Use below line in seekbar xml file
android:thumb="#drawable/seekbar_thumb_draw"
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="#drawable/seekbar_thumb_draw" />
//seekbar_thumb_draw.xml
<?xml version="1.0" encoding="utf-8"?>
<item>
<shape>
<size
android:height="40dp"
android:width="40dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:drawable="#drawable/seekbar_thumb_image"/>
seekbar_thumb_image is image for thumb that u want
Photshop the exact size that you want. Then save it in your drawables folder. Then reference it in the xml code for your seekbar.
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="wrap_contentt"
android:layout_height="wrap_content"
android:thumb="#drawable/seek_thumb_verywidebar" />

Categories

Resources