查看http://developer.android.com/training/basics/fragments/index.htmlFragment
_
基本上你会有两个布局文件夹,就像你建议的那样。
- res/layout/main.xml(用于portiat)
- res/layout-land/main.xml(用于横向)
您将把您的界面构建成Fragment
s,并将其中两个放在横向,一个放在纵向。例如
public class ContactListFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.contact_list, container, false);
// do your work
return view;
}
}
public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// configure your fragments here.
}
}
资源\布局\main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.example.android.fragments.ContactListFragment"
android:id="@+id/contact_list_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
res\layout-land\main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.example.android.fragments.ContactListFragment"
android:id="@+id/contact_list_fragment1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.android.fragments.ContactListFragment"
android:id="@+id/contact_list_fragment2"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>