Reputation: 140
I'm actually coding an app for Android and I need some help to do something. I need to do a kind of popup message with this image: http://img716.imageshack.us/img716/9331/postitz.png. This image must have 2 TextView, one of them is a title and the other one is the message.
I have tried some options like Dialog with its own layout, own style, but the image fills all the screen instead of wrap the content of the TextViews. I have also tried to do it with a new Activity and occurs the same, the Image fills all the screen.
My actual layout is this:
<?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:gravity="center_vertical"
android:background="@android:color/white">
<LinearLayout
android:id="@+id/img_postit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/postit"
android:orientation="vertical">
<TextView
android:id="@+id/note_titulo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
<TextView
android:id="@+id/note_descr"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
</LinearLayout>
</LinearLayout>
But I have tried with a lot of different combinations, RelativeLayout, FrameLayout, and I cannot find the solution to do this.
Any idea of how to resolve it?.
Thank's for all.
Upvotes: 0
Views: 274
Reputation: 488
final Dialog dialog_my = new Dialog(FIRST.this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog_my.setContentView(R.layout.about_us); //<PUT YOUR LAYOUT ID HERE>
TextView date = (TextView) dialog_my.findViewById(R.id.date);
TextView thought = (TextView) dialog_my.findViewById(R.id.thought);
TextView ok = (TextView) dialog_my.findViewById(R.id.ok);
TextView link = (TextView) dialog_my.findViewById(R.id.link);
TextView contact = (TextView) dialog_my.findViewById(R.id.contact);
WindowManager.LayoutParams lp = dialog_my.getWindow().getAttributes();
lp.dimAmount = 0.0f;
dialog_my.getWindow().setAttributes(lp);
dialog_my.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog_my.show();
Upvotes: 0
Reputation: 7110
you said you used as a new activity. Did you use android:theme="@android:style/Theme.Dialog
in your manifest file?
And be sure that the image is little bit smaller one such that it will be suitable to act as a pop up.. If you used a dialog what exactly is the problem? Didnt you get the dialog as a pop up ? (i think the image is larger so that it might fill the entire screen)
Upvotes: 1
Reputation: 6141
Create your own class extending dialog.And use layout like following. I use this in one of my apps and the dialog window is wrapped around the buttons :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/ll2"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="@+id/ll1"
android:gravity="left"
android:orientation="horizontal"
android:paddingBottom="5dp" >
<RadioButton
android:id="@+id/start"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/stop"
android:background="@drawable/start_on"
android:button="@android:color/transparent"
android:checked="true" />
<RadioButton
android:id="@+id/stop"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/stop_off"
android:button="@android:color/transparent" />
<RadioButton
android:id="@+id/restart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/stop"
android:background="@drawable/restart_on"
android:button="@android:color/transparent" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/lltext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/detail_credit"
android:layout_below="@+id/ll2"
android:layout_marginBottom="15dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/startText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/stopText"
android:text="@string/start_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/stopText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="@string/stop_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/restartText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/stopText"
android:text="@string/restart_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<Button
android:id="@+id/dialogButtonOK"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_below="@+id/lltext"
android:layout_centerHorizontal="true"
android:text="OK" />
</RelativeLayout>
Upvotes: 1