【问题标题】:Screen Orientation and Fragments屏幕方向和片段
【发布时间】:2012-04-18 16:04:23
【问题描述】:

有一件事真的让我发疯。屏幕布局未正确从陆地变为纵向。

我的布局文件夹中有两个文件夹来处理方向和 .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>

另一个:

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>

我的主要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);
    }
}

如果屏幕是纵向而不是旋转,它会正确改变。

问题是相反的。如果屏幕是陆地,那么旋转对布局没有任何变化。事实上,它正确调用了 onCreate 方法,但布局并没有更改为纵向! =/

有人知道为什么吗?

【问题讨论】:

    标签: android android-layout fragment android-orientation


    【解决方案1】:

    问题可能是您的肖像位于正常尺寸屏幕的文件夹中,而您的横向位于大尺寸屏幕的文件夹中。也许您可以将 layout-large-land 更改为 layout-land (如果您的设备具有普通屏幕)或将 layout 更改为 layout-large (如果您的设备具有大屏幕)并查看它是否有任何作用。 (注意:即使它有一个大屏幕,将它放在 layout 和 layout-land 中仍然可以工作。

    【讨论】:

    • 嗯...我已经改变了文件夹名称,就像你说的(两种组合),但仍然不起作用!这和以前一样! =/
    • 不知道这是否意味着什么,但我只在虚拟设备上测试过。 Android 2.3.3,API 级别 10,屏幕尺寸:720x960,密度:240。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 2014-04-14
    • 1970-01-01
    相关资源
    最近更新 更多