4

I have an activity in android and I want to add a fragment which would appear as in the image below. I want it to have the shape shown and be semi-transparent so that the activity can be seen in the background. Two questions : 1) How do I set the shape of a framelayout? I assume I define the shape in XML and save it as a XML file but which attribute do I use to set the frame layout to have that shape. 2) how do I make the fragment semi transparent, I assume I would use a semi transparent color as the background, but I am not sure.

enter image description here

Alk
  • 5,215
  • 8
  • 47
  • 116

1 Answers1

0
  1. For transparency, use alpha=" (float) value" on your fragment layout (container) in your activity_main.xml.
  2. For rounded corners check this solution this solution, adding background also on fragment layout container. Also apply padding to this container.
Community
  • 1
  • 1
Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
  • I added it to the frame layout of the fragment but I don't see any changes on the preview – Alk Jul 03 '15 at 20:25
  • You should be able to see on Preview in `activity_main.xml`, not in your fragment layout. If you used code from my link, it is very light, so you may not see it on white background activity, so try to change it background to ex. red. Check this code, it works - http://pastebin.com/TeQneAt4 – Damian Kozlak Jul 03 '15 at 20:30
  • thanks, and in this under fragment I would also add `alpha = "0.5"` for example right – Alk Jul 03 '15 at 20:52
  • setting `alpha = "0.5"` in `activity_main.xml` for layout, which is layout fragment container for your fragments, will result that all layouts ex. `some_fragment_layout.xml` will be already transparent, you don't need to set `alpha = "0.5"` in `some_fragment_layout.xml` – Damian Kozlak Jul 03 '15 at 20:59
  • If you need only one fragment semi-transparent, you can call `((ViewGroup) getView().getParent()).setAlpha(0.5f)` in Overrided `onViewCreated` in your fragment. – Damian Kozlak Jul 03 '15 at 21:15