Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old 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
Default 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);

}

krishnan is offline  
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:12 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo