0

I am interested in creating some kind of View or Fragment that takes up a small amount (~33%) of the current View. This overlayed View will use the camera as input. I think this is analogous to the YouTube app's small video playing in the corner.

I have a crude sketch of what I want (below). I don't need a full writeup, just a starting point.

enter image description here

TCCV
  • 3,142
  • 4
  • 25
  • 30
  • what do you mean `a fragment running another activity`? – njzk2 Dec 20 '13 at 18:59
  • Currently, I use an intent to launch another activity that takes the entire screen and then returns. If it's possible, I'd like to make it only show as an overlay. I can perhaps use another method to invoke the View, but I'd like the overlay effect. – TCCV Dec 20 '13 at 19:17
  • I guess you can do this with `Fragment`s instead of another `Activity` and hosting it in `FrameLayout`. – Blo Dec 20 '13 at 19:20

1 Answers1

1

Not sure it is the good way for it, but you can try with a FrameLayout to host a Fragment and make the FrameLayout with a background transparent (if you don't know what is FrameLayout, in few words it serves to overlap views. I writed an answer on this). The layout of your Parent Activity (FragmentActivity) may be something like this:

<FrameLayout 
     android:id="@+id/FragmentContainer"
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent" android:layout_height="match_parent"
     android:background="@android:color/transparent" >

     <TextView
          android:layout_width="match_parent" android:layout_height="match_parent"
          android:text="I'm a text of the content" />

</FrameLayout>

And the Fragment may be as below:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" >

    <LinearLayout 
        android:layout_width="match_parent" android:layout_height="250dip"
        android:background="@color/blue"
        android:layout_alignParentTop="true" >

        <TextView
            android:id="@+id/ReaderEdit"
            android:layout_width="match_parent" android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="I'm a text in a fragment" >

    </LinearLayout>

</RelativeLayout>  

And then when you initialise your Fragment in the FrameLayout, you set hide() and show() methods for display it. For this, use FragmentSupportManager in your FragmentActivity and add() or replace() methods like the example below:

// Initialize your fragment: 

FragmentTransaction mTransaction = this.getSupportFragmentManager().beginTransaction();
Fragment mFrag = new MyFragment(); // call your Fragment Class
mTransaction.add(R.id.FragmentContainer, mFrag, null).hide(mFrag).commit(); // add to the Container (FrameLayout) and hide it
// don't forget to commit at the end of every FragmentTransaction

// To display your fragment: 

FragmentTransaction mTranDisplay = this.getSupportFragmentManager().beginTransaction();
mTranDisplay.show(mFrag).addToBackStack(null).commit(); // pass the Fragment to show + add the BackStack method (when the user press back button, the Fragment disappears without quit the Activity)
mTranDisplay.setCustomAnimations(R.anim.slide_in, 0, 0, R.anim.slide_out); // you can make an animation to the BackStack method, here it's a slide in/out from top to bottom

I think there is a proper way to do this. Maybe you can check this library and see, break, rebuild,... the code.

Hope this helps.

Community
  • 1
  • 1
Blo
  • 11,903
  • 5
  • 45
  • 99