Making of shadow

1 ) I want to know how to add shadow to a layout
and able to keep it in certain position from the layout .
2 ) I also want to make this shadow Enable and Disable through "Java " at certain positions (Eg : For 10 images , i can be able to place shadow Enable/Disable wherever is needed ).

Usually, that is handled by the android:elevation attribute. This takes a dimension (value or resource). The higher the dimension, the bigger the drop shadow will appear.

I do not know what this means, sorry.

You can call setElevation() on a View to change its elevation. Setting it to 0 will remove the drop shadow.

Thank you

  1. able to keep it in certain position from the layout -> Distance(coordinates) between shadow and image , if possible

I still am uncertain what you mean.

If you mean how big the shadow is (how far it extends from the view), if you use elevation, larger elevation values give you larger shadows.

If that is insufficient, you will need to fake your own shadow:

  • Put the widget that needs the shadow in a FrameLayout
  • Create some drawable that will render the shadow
  • Apply that drawable to the FrameLayout as its background
  • Use bottom and either start or end padding in the FrameLayout to allow the background to appear

download
I want to keep shadow like shown in pic

At this point, I cannot provide you with further advice. Either use elevation for Android’s standard drop shadow option, or create your own (e.g., using the FrameLayout as I mentioned previously).

Thank you
I want to know that When i try to acces dimen from Java (var=context.getResources().getDimensionPixelSize(R.dimen.value)
I got an error : Null object reference on getResources
How to resolve this and is it possible to pass constant value via dimens file

Either context itself is null, it was not created correctly, or it has been destroyed.

In general, if you want help with crashes, you need to provide a full stack trace, plus a fairly complete set of code that pertains to that stack trace. That is not unique to me and this discussion board — it is fairly common in most support places (GitHub issues, Stack Overflow, etc.).

Sorry, but I do not know what you mean. You are welcome to define dimension resources in values resource directories (e.g., res/values/), and you are welcome to reference those dimensions from your Java/Kotlin code by calling methods on a Resources object. However, to get a Resources object, you need a valid Context. And, for something like a dimension, I recommend that it be an Activity, not some arbitrary other Context.

Declaration of a Constant value like 594(not in dp ) in dimens file is allowed

You can have <integer> resources for plain integers, just as you can have <dimen> resources for dimensions.

1 Like

Thank you
I want to know the difference between following code…
1.WindowManager.LayoutParams.MATCH_PARENT
2. ViewGroup.LayoutParams.MATCH_PARENT
I also want to know that
a ) If WindowManager is subclass of ViewGroup,then accessing parent data member which is MATCH_PARENT via subclass not a problem but there might be any chance of ambiguity when MATCH_PARENT is accessed multiple times via WindowManager, if there is ambiguity then calling it via ViewGroup is a better solution or not

They are identical, as MATCH_PARENT is defined on ViewGroup.LayoutParams, and WindowManager.LayoutParams is a subclass of ViewGroup.LayoutParams.

It is not, though WindowManager.LayoutParams is a subclass of ViewGroup.LayoutParams.

I cannot answer that, sorry.

Thank you
I want to apply Transparent property to the text which is present at the bottom part of popup, while scrolling it should not have that transparent property (i.e, completely visible)
how to do this

Sorry, but I do not know. You are using something for the scrolling (ScrollView, NestedScrollView, ListView, RecyclerView, etc.). Look for a listener that you can register for scroll events, then modify your view as needed based on those events.

How to set transparent property at a specific area of the textview .
Please provide some reference code .

Using a ForegroundColorSpan or BackgroundColorSpan, you can affect the color of a section of text in a TextView. Beyond that, I am not aware of any options that match my interpretation of what you are describing.

download (1)

Please consider the dots as Text that needs to be Transparent and the same text not to be transparent while scrolling.

Sorry, but I have no idea how to do that.

Using android:fadingEdge=“vertical” , I get fading on both Top and Bottom part of my Textview . How to apply this only on bottom part of the Textview

I have never used this attribute directly. AFAIK, it’s usually handled for you by scrolling containers like ScrollView. You could look into getTopFadingEdgeStrength(), but this would require you to make a subclass of TextView.