November 4th, 2011, 06:08 PM
|
#1 (permalink)
|
|
New Member
Join Date: Jun 2010
Posts: 6
Device(s):
Thanks: 1
Thanked 1 Time in 1 Post
|
How to center align Fragments
Hi
Please see the codelet that we are using to center align the player.
I would appreciate any kind of pointers to fix the issue.
Layout Structure:-
1) I have a list view to display a movie title/name
2) I have a fragment to display the movie
Iam are trying to center align the fragment by setting its gravity.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Layout files
HTML Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="match_parent">
<LinearLayout android:id="@+id/listLayout" android:layout_width="140dip" android:layout_height="match_parent">
<ListView
android:id="@+id/movies_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout android:id="@+id/fragmentLayout"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="match_parent" android:gravity="center">
<fragment class="com.application.PlayerFragment"
android:id="@+id/titles" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_gravity="center_vertical|center_horizontal"/>
</LinearLayout>
</LinearLayout>
Code:
public class PlayerFragment extends Fragment implements SurfaceHolder.Callback {
static SurfaceView surfaceView;
SurfaceHolder mSurfaceHolder01;
onCreate()
{
surfaceView = new SurfaceView(getActivity().getApplicationContext());
mSurfaceHolder01 = surfaceView.getHolder();
mSurfaceHolder01.addCallback(this);
mSurfaceHolder01.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
}
#######################################################################
## Here is surface change callback I am trying to center align the fragment when
#######################################################################
public void surfaceChanged(SurfaceHolder surfaceholder, int format, int w, int h) {
/////////////////////////////////////
// Not working/ No change on Fragment
LinearLayout fragmentLayout = (LinearLayout)getActivity().findViewById(R.id.fragmentLayout);
//LinearLayout linearLayout = (LinearLayout)getActivity().findViewById(R.id.fragmentLayout);
//((LinearLayout.LayoutParams)linearLayout.getLayoutParams()).gravity = Gravity.RIGHT;
////////////////////////////////////////
// It working on the list view/
//LinearLayout linearLayoutMovie = (LinearLayout)getActivity().findViewById(R.id.listLayout);
//linearLayoutMovie.setVisibility(View.GONE);
}
|
|
|