2
有一件事情真的让我发疯。屏幕的布局没有正确地从陆地变为肖像。屏幕方向和片段
我在我的布局文件夹中两个文件夹来处理方向的事情,在这.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方法,但布局不会改变为肖像! =/
任何人都会知道为什么?
那么...我已经改变了文件夹名称就像你说的(两种组合),但仍然无法正常工作!这跟以前一样! =/ – trebew 2012-04-19 11:12:48
不知道它是否意味着什么,但我只在虚拟设备上测试过。 Android 2.3.3,API等级10,屏幕尺寸:720x960,密度:240。 – trebew 2012-04-19 11:15:43
还有更多的消费? – trebew 2012-04-20 18:29:20