1

Is it possible to create a Button over a fragment activity?
I tried by dragging it on the screen but he doesn't allow me to do it Like that so, any alternative?
There's any way to do it from XML?

Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43

1 Answers1

0

You can use ViewStub for this: ViewStub is a View that is inflated lazily.

You can declare a ViewStub in an XML file like this:

<ViewStub android:id="@+id/stub"
android:inflatedId="@+id/subTree"
android:layout="@layout/mySubTree"
android:layout_width="120dip"
android:layout_height="40dip" />

The android:layout attribute is a reference to the View that will be inflated next to a call of inflate(). So

ViewStub stub = (ViewStub) findViewById(R.id.stub);
View inflated = stub.inflate();

When the method inflate() is invoked the ViewStub is removed from its parent and replaced with the right View (the root view of mySubTree layout).

If you want to do this pragmatically then your code should be something like:

ViewStub stub = new ViewStub(this);
stub.setLayoutResource(R.layout.mySubTree);
stub.inflate(); 

Here mySubtree is layout you want to show after inflating Activity or Fragment.

Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43