Show a view with a hole - android

I'm trying to create a view as tutorial for my activity. I need to show only some text with a translucent background an leave a "hole" transparent to see the background button of the original activity. I can use a framelayout with two different sub-layout (the original one and the tutorial one) and I can set visible/invisible the tutorial layout. The problem is: I don't know how I can create a "hole" in the tutorial sub-layout. How can I do?

background colors should transparent, opaque
I hope, it will work for you.
circle_background.xml file
<shape
android:shape="ring"
android:useLevel="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/blue_pressed" />
</shape>
view_background.xml
<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:background="#drawable/circle_background"
>
//add more views if u wanto
</LinearLayout>

For create a "hole" or circular view you need create a drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#android:color/transparent" />
</shape>
And create a imageview in the position and size that you want and set this drawable like background.
Also you can use #00000000 intead #android:color/transparent
Or use TutorialView library on github

Related

How can we set shadow effect for View in Android?

In my Android application I have one view it may be ImageView or TextView how can I set shadow effect for View in android? I have set the shadow by using the following code, but it won't work:
view.setElevation(130)
Please help me to solve this
You can create your own "shadow view"
<View
android:id="#+id/shadow_view"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_gravity="bottom"
android:background="#drawable/shadow_gradient" />
and add the shadow drawable to it:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:endColor="#android:color/transparent"
android:startColor="#8f000000" />
</shape>
The height is up to you, to experiment and see what works best for you as is the angle and start colour of the drawable. You just need to align this view layout to any view layout you want to have a shadow and you are good.

splash screen and gradient

Here's my aching point. I'm new to android developoment and I want to create the splash screen to an app. presently, after searching in this forum, i found methods of implementing the splash screen from a picture but that's not what i want. I want the splash screen to be a color with a varying gradient. Attached to this question is a picture to illustrate what i mean.
Unfortunately, couldn't paste an image due to my low reputation points. Nonetheless, here's a link to an gradient image.
Further explaining, i want the color to be generated by either java or xml code dynamically so that, I won't have to bother about different screen sizes as all I'll have to do is to generate everything for full screen display. What's I'm trying to avoid is using picture assets if possible.
Help Plz. Thanks
create a shape, add it to drawables like : <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/gradient_start" <!--this first color -->
android:endColor="#color/gradient_end" <!--this second color -->
android:angle="-270" /> <!--gradient angle -->
</shape>
and then on your splash.xml background, set background to the shape
add
<LinearLayout
android:id="#+id/ranking_order"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_grad"
/>
Also gradients and colors may be declared directly into splash.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!--<color android:color="#2196F3"/>-->
<shape android:shape="rectangle">
<gradient
android:startColor="#2196F3"
android:endColor="#1976D2"
android:angle="-90"
/>
</shape>
</item>
<item>
<bitmap
android:src="#drawable/logo"
android:gravity="center"
/>
</item>
</layer-list>

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>

Android: Applying rounded shape to a linear layout

I am gonna to create the a alert dialog box in android with rounded shape.
I follow many threads in this site. Create a shape.xml and place it drawables
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="5dp" android:color="#FF0000" />
<corners android:bottomRightRadius="20dp" android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp" android:topRightRadius="20dp"/> <solid android:color="#FFFF00"/>
And apply the above shape to the linearlayout.
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/transparent" >
<LinearLayout android:layout_width="200dip"
android:layout_height="60dip"
android:orientation="vertical"
android:background="#drawable/shape">
</LinearLayout>
However, there is still have a rectangle border and back color outside the dialog box. That is not what I want.
I have search for a long time I dont know how to fix it.
I aimed to make it transparent outside the corner of the dialog box layout. Thank you so much!
Screen Shot: http://postimg.org/image/3xbnmquyt/
For the shape you want I found the default one on Android Studio, this:
android:background="#drawable/abc_menu_dropdown_panel_holo_light"
Apply it to your LinearLayout, It is exatcly what you're talikng about and you don't need to create other xml files in the drawables. To see how It looks like see my answer here:
Android View shadow
Hope I helped you.
Remove the stroke tag because it is used for creating the border. Also you shouldn't use gradient and solid together because they exclude one another.
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

Transparent View?

How can I do transparent view. Can anybody help me?
I want to do just like this:
create one layout and make theme as dialog in your manifest
and in your layout set background as android:background="#885A2720"
EDIT:
check this layout in your view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:minWidth="250dp"
android:minHeight="380dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#885A2720" style="#android:style/Theme.Holo.Dialog">
</LinearLayout>
You should just be able to change the opacity/alpha of the overlay.
If you would use relativeLayout then use imageView with height and width match_parent.
And set alpha of an image to 150dp.
Use drawables to draw the rectangles
For complete transparency, use the following drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#00000000" />
<stroke android:width="0.3dip" android:color="#2f4f4f"
android:dashWidth="7dip"
android:dashGap="7dip"/>
</shape>
If you want to set % transparency, u can set the "Alpha"property of the widget used. Note that a text box with nothing in it can help you achieve that.

Categories

Resources