调查Fragment
s http://developer.android.com/training/basics/fragments/index.html
基本上,您将拥有两个布局文件夹,就像您建议的一样。
- RES /布局/ main.xml中(用于portiat)
- RES /布局,土地/ main.xml中(用于景观)
你建立你的界面进入Fragment
小号并将其中两个放在风景中,另一个放在肖像中。例如
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>
资源\布局,土地\ 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>
哇,我永远不知道我们可以做到这一点,太棒了。但是我想要的是在景观中并排的两列联系人姓名。可能吗?我更新了这个问题,所以不会造成混淆,对不起 – hrsetyono
在这种情况下,您会希望使用相同的'ContactListFragment'两次,并且只显示您想要的内容。我将更新示例 – Kirk
谢谢,我会先尝试 – hrsetyono