I have added a view to a layout which occupies a part of my screen. To this layout I want to add another layout which will be transparent. On this layout there should be only two lines which will scroll over the background layout. This I am doing so that my background layout is not invalidated and only the foreground is invalidated.
How can I add another layout which will be transparent?
Use FrameLayout as a parent layout and stack it up with as many layouts as you want. Thats one part of the answer. To make a layer (a layout in this case) transparent, set the alpha value in its background (a color) to 0. For instance android:background="#00777777" sets a background which is translucent with a dull gray.
You get the idea.
Use fram layout, which will allow you to add two views on each other.
Related
I'm creating a simple custom view. My view inherits from AppCompatImageButton with the goal of drawing some simple geometric shapes for my custom button and animating them.
If my XML view contains:
android:background="#color/transparent"
My view draws correctly inside a vertical LinearLayout, even though the android:background seems to otherwise do nothing. However, if I leave out android:background, the top and bottom displays an additional unwanted gap between the custom views.
The documentation says these two are "Related":
View.setBackgroundResource(int resid)
android:background
I've tried calling setBackgroundResource(R.color.transparent) in my Java initialization code, thinking this would do the same thing as XML android:background, but the unwanted padding won't go away. Here's a screenshot that shows the view without the android:background.
With android:background, the image fills the entire height not leaving the gap at the top and bottom.
How can I get my custom view to fill the entire drawing area without forcing an artificial android:background into the XML? The solution will also need to work if the programmer creates the custom view in Java without XML.
Thx.
I have a custom semicircle Liner Layout in which I want to add colored views , but these views do not match the custom shape(or stay within the bounds of the Liner Layout)
When I assigned custom shape to the views
custom shape
when I assign MATCH_PARENT to the views
match parent
I want the views to fill the inside of the Liner Layout while retaining the shape of it, is there any way this can be done?
You can't create a custom shape to a view. VIews are always rectangular. If you mean you have a custom background, that doesn't make the view group a custom shape, or effect the layout of views within the group. If you want to do that, you need to override onLayout (and possibly onMeasure) and layout the individual children with the bounds you expect them to be in. Do not be surprised if you get some ugly or non-functional results like this- views weren't made to be circular.
Given an activity with multiple views, is there a way to have the background dimmed while one view retains its original state (not dimmed)?
I have an existing layout with views and I am adding a dimmed framelayout over the existing layout, and would like to keep one of the child views in the existing views "lightened up" in its state while the dimmed framelayout view encompasses around it.
The way I know how to do this won't be very elegant for your particular use case. But I'll explain it in case you don't find a better solution.
Wrap your entire layout in a RelativeLayout, and then add a LinearLayout with fill_parent parameters on top of it, and a partially transparent black background. Adjust the alpha and RGB to how you see fit.
Now you can add your undimmed view to the RelativeLayout on top of the dimming. Since you're no longer inside the FrameLayout container, you'd have to adjust the positioning of this layout, and manually remove and re-add these two views for dimming and undimming, hence this is not a very elegant solution.
The following screenshot illustrates a simple example of what I have now:
What I'd like to achieve, is that the selected (blue) view not be clipped at the boundary of the red container. My first try was clipChildren="false", which causes the blue view to expand outside of its borders, filling the the red area. I just want to see the portion overlaying the green area.
I think you'll have to float the blue on top of both the red and green. You can't have a child outside of its parent ViewGroup (AFAIK). You'll need to redesign your layout.
Getting what you want should be pretty easy, though. I don't use the graphical designer, so would need XML.
FrameLayout with LinearLayout inside to show the Red/Green, then another Linear or Relative after the first LinearyLayout (inside the FrameLayout). With LinearLayout, I'd align right, and give the blue element some padding.
It may be possible to do this all with RelativeLayout, but I tend to stay away from it.
Essentially what you're looking for is overlapping views. This can be done with a FrameLayout. For information on how to do this, please checkout this example.
I have several Views in my Activity. I want to draw a Drawable over these views.
The Drawable should be on top of the views (that means it hides the views below it.
The Drawable may appear over several views (that is I can't just draw it in one view).
How can this be done?
Thank you
The FrameLayout allows you to have overlapping views. This is often used if you have some sort of background, with widgets over it.
Maybe you could use a Dialog or view with Dialog Theme with your drawable as the background?