trebew
trebew

Reputation: 121

Screen Orientation and Fragments

there's a thing that is really making me crazy. The layout of the screen isnt changing from land to portrait correctly.

I have two folders in my layout folder to handle the orientation thing and .xml files in it, like this:

layout\main.xml  

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

<fragment
    android:id="@+id/menu"
    android:name="br.trebew.odonto.MenuData"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<fragment
    android:id="@+id/princ"
    android:name="br.trebew.odonto.FragList"    
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

and the other:

layout-large-land\main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="290dp" 
    android:layout_height="fill_parent">

<fragment
    android:id="@+id/menu"
    android:name="br.trebew.odonto.MenuData"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<fragment
    android:id="@+id/princ"
    android:name="br.trebew.odonto.FragList"    
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

<fragment 
    android:id="@+id/fdetalhe"
    android:name="br.trebew.odonto.DetalheFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

My main java class is OdontO.java, which is:

public class OdontO extends FragmentActivity implements OnDateChangeListener, OnAgendaItemClickListener {

FragList fList;
MenuData mData;
DetalheFragment frag_detalhe;

private boolean detalhesInLine;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);   

    Log.i("LayoutOr", "Entrou no onCreate OdontO");

    mData = (MenuData) getSupportFragmentManager().findFragmentById(R.id.menu);
    fList = (FragList) getSupportFragmentManager().findFragmentById(R.id.princ);  

    frag_detalhe = (DetalheFragment) getSupportFragmentManager().findFragmentById(R.id.fdetalhe);
    detalhesInLine = (frag_detalhe != null && 
            (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE));
    if (detalhesInLine) {
        fList.enablePersistentSelection();
    }
    else if (frag_detalhe != null) {
        frag_detalhe.getView().setVisibility(View.GONE);
    }
}

If screen is portrait than rotating it changes correctlly.

The problem is the reverse. If the screen is land than rotation has no change on the layout. Infact it calls the onCreate method correctly, but the layout doesnt changes to portrait! =/

Anyone would know why?

Upvotes: 2

Views: 626

Answers (1)

DevinFalgoust
DevinFalgoust

Reputation: 134

The problem may be that your portrait is in a folder for normal-sized screens and your landscape is in a folder for large-size screens. Maybe you could change layout-large-land to just layout-land (if your device has a normal screen) or change layout to layout-large (if your device has a large screen) and see it if does anything. (Note: even if it has a large screen, putting it in layout and layout-land should still work).

Upvotes: 1

Related Questions