Set fragments' positions in android activities -


i have fragment should shown in activity under fragment

in xml of fragment tried use:

<relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/second_fragment"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginbottom="10sp"     android:layout_below="@id/first_fragment">       <textview          android:id="@+id/mytext"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text=" "         android:focusable="false"         android:clickable="false"         android:textsize="20sp"         android:padding="5sp"         android:layout_centerhorizontal="true"/>     </relativelayout> 

(please note android:layout_below="@id/first_fragment" in layout tag)

i have tried this:

<relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/first_fragment"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginbottom="10sp">          <textview          android:id="@+id/mytext"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text=" "         android:focusable="false"         android:clickable="false"         android:textsize="20sp"         android:padding="5sp"         android:layout_centerhorizontal="true"         android:layout_below="@id/first_fragment"/>      </relativelayout> 

(please note android:layout_below="@id/first_fragment" in textview tag)

in both cases application compile , run second fragment shown on top of screen instead of after first one.

please consider i'm adding fragments programmatically using fragmenttransaction , add second fragment after having added first one, in same transaction

can please tell me what's wrong?

thank-you

you can use framelayout (viewgroup) in activity xml hold fragment, add fragment object using add or replace

fragmenttransaction.replace(r.id.framelayoutid, yourfragmentobject); 

so can align wish


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -