3

We know that default shape of Activities is rectangular in Android. I have made a modal activity using the following style:

<style name="Theme.TransparentD0" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@color/semi_transparentD0</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

enter image description here

Now I have a rectangular modal Activity. Is it possible to create a circular shaped modal Activity? How?

I mean I want to change the shape of my modal Activity to Circle.

Bob
  • 22,810
  • 38
  • 143
  • 225
  • If your background is circular won't it be circular ? I mean what exactly are you sking for? Us to change the shape?? – cjds Dec 25 '12 at 09:25
  • I mean I want to change the shape of my modal Activity to Circle. – Bob Dec 25 '12 at 09:28
  • But if your background is a circle. And every picture is circular. Your activity would look circular. So..... Doesn't that become a designer problem. I'm sorry but I fail to see how this is a programming question? – cjds Dec 25 '12 at 09:31
  • Maybe you could clarify? What would your approach be to changing it? – cjds Dec 25 '12 at 09:31
  • the black area in my activity is the default LinearLayout. The shape of a LinearLayout is rectangular. How can I make it Circular? – Bob Dec 25 '12 at 09:35
  • If it is easy please send me a sample – Bob Dec 25 '12 at 09:40

1 Answers1

7

You can create Dialog based Activity.

Set theme for your Activity in AndroidManifest.xml:

<android:name="YourActivity"
   ...
   android:theme="@android:style/Theme.Dialog"/>

in YourActivity class create your carousel Gallery

Create such kind of Layout for Activity: enter image description here

This is the sample layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res/com.sits.TaxiMoldova"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:background="@android:color/transparent">

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/backgroundCircleImage"
            android:background="@drawable/bg"
            android:layout_centerInParent="true"/>

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_centerInParent="true"
            android:id="@+id/contentLayout"
            android:background="@android:color/transparent">

        <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="button 1"
                android:id="@+id/button"/>

        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="button 2"
                android:id="@+id/button1"
                android:layout_gravity="center"/>
    </LinearLayout>

</RelativeLayout>

Resources: circle with transparent background

Result: enter image description here

Background is not black, 100%. Instead of that black background would be your Activity (parent of Modal Activity). This is the idea, play around with the proportions and everything will be fine :)

Veaceslav Gaidarji
  • 4,261
  • 3
  • 38
  • 61
  • How can I make it Circular? – Bob Dec 25 '12 at 09:16
  • what kind of meaning you put in the word "circular"? "Circular" - in the form of a circle? – Veaceslav Gaidarji Dec 25 '12 at 09:23
  • Exactly what I need. Can you give me a sample? How to create it? – Bob Dec 25 '12 at 09:39
  • Your solution is OK for my problem. But for common smaller rectangular Activities it is possible for user to click the behind activity using `LayoutParams.FLAG_NOT_TOUCH_MODAL` flag and in your solution it is impossible. – Bob Dec 25 '12 at 10:05
  • For example in my code that its picture is in question, I can make it possible for user to click on elements of parent Activity which is around the modal activity. – Bob Dec 25 '12 at 10:09
  • I think it is possible, your activity can fill all device screen area, and also can fill just part of screen in center. Or you can create layout (like in sample) and set this layout for your Dialog like content (setContentView() method) – Veaceslav Gaidarji Dec 25 '12 at 10:17
  • In that situation the area between rectangular activity and circular picture (corners) is transparent but it is not clickable and user can not click parent Activity's elements that are located in that are. – Bob Dec 25 '12 at 10:38
  • yeah, you are right. This link can be useful - http://stackoverflow.com/questions/12705023/how-to-make-transparent-area-as-untouchable-for-imageview-in-android. Or you can disable touch for background circle image (have not tried it, this is the idea) – Veaceslav Gaidarji Dec 25 '12 at 10:47