简体   繁体   English

屏幕方向和碎片

[英]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: 我的布局文件夹中有两个文件夹,用于处理方向文件和.xml文件,如下所示:

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: 我的主要Java类是OdontO.java,它是:

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! 实际上,它会正确调用onCreate方法,但布局不会变为纵向! =/ = /

Anyone would know why? 有人会知道为什么吗?

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). (注意:即使屏幕很大,将其放在布局和布局区域中也应该可以使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM