11

i want to make an activity which appears on half screen (JUST LIKE DIALOG BOX BUT NOT DIALOG BOX) i want to add some text,switch buttons and labels on it ?

i tried Dialog Boxes but it does not satisfy me so now i want to resize activity. HELP

Thanks in advance

  • 1
    This is insane xD But you can use floating window for such behaviour. – berserk Jun 16 '14 at 14:29
  • @berserk will u please guide me that ho can i do it ? because i am going to experiment it first time. i shall be very thankful to u –  Jun 16 '14 at 14:33
  • Maybe this can help you: http://stackoverflow.com/questions/18124153/how-to-add-a-floating-view-to-android-window-manager-and-listen-to-system-hardwa – berserk Jun 16 '14 at 17:42

1 Answers1

5

Easy. Just use fragments! With fragments, you will have complete control of size and location of everything. See my example

Here is my main xml. This is two separate fragments. Each takes up about a quarter of the screen.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:padding="12dp">

<fragment
    android:name="com.diamond.home.fragments.TopFragment"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

 <!-----here, add the rest of your xml for your main activity -------->

Your main activity that will display these fragments will not need to do anything to display your fragments because your XML will already call the fragments in for you. NOTE: if you want to display the fragment only at certain times, you can reference the fragment from the xml, and set the visibility to GONE. Then when you need it, set it to VISIBLE.

Then, Create fragment classes like so:

 public class TopFragment extends Fragment {


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragments_top, container, false);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

   //do your stuff for your fragment here


}

So you will also need to create another xml layout for your top-fragment. In that, you can add buttons, text views or what have you. Hope this helps. If you have any questions, feel free to ask.

Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
  • 1
    if i want to do show a fragment dialog from activity class what should i have to o , i never experienced fragments, –  Jun 16 '14 at 19:11
  • Just make your main activity (that shows the dialog) extend FragmentActivity instead of Activity. Take a look at these tutorials. http://www.vogella.com/tutorials/AndroidFragments/article.html. – Chad Bingham Jun 16 '14 at 19:44
  • There a two ways, that I can think of, that you might go about doing it. The way I listed above, or instead of a ` – Chad Bingham Jun 16 '14 at 19:48
  • i cant mark it because i have only 1 reputation and it require 15 to mark an answer , can u please vote my question it will help me to increase reputation –  Jun 17 '14 at 02:01
  • Ah, ok. Well accept it when you get a chance. Thanks! – Chad Bingham Jun 17 '14 at 02:02
  • Ok i will Accept it but if u can increase my reputation i will do it now **thanks** –  Jun 17 '14 at 02:10
  • i am feeling so much dificulty in making fragment dialog can u please help me if i snd you my code via email can u do some thing for me? –  Jun 17 '14 at 02:14