巨大的android布局问题
我刚开始使用Android,我正在做一个简单的应用程序,我希望它看起来像这样:巨大的android布局问题,android,performance,android-layout,Android,Performance,Android Layout,我刚开始使用Android,我正在做一个简单的应用程序,我希望它看起来像这样: ------------------------------------------- | | | | | T A B | T A B | T A B | | SELECTED | | | |---------------------------
-------------------------------------------
| | | |
| T A B | T A B | T A B |
| SELECTED | | |
|-----------------------------------------|
| |
| VIEW FLIP CONTENT |
| |
| |
| |
| |
| |
| |
| |
| |
-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
也就是说,我有一些选项卡,每个选项卡都有一个视图翻转组件。这使他们能够拥有内部“选项卡”。问题是,使用此配置,我必须在单个活动上运行所有内容!此外,我的布局越来越大(见附图)。我怎样才能解决这个烂摊子?是否将每个选项卡作为单个活动运行
可以将所有选项卡放在不同的活动中。为父活动创建简单布局,如下所示:
-------------------------------------------
| | | |
| T A B | T A B | T A B |
| SELECTED | | |
|-----------------------------------------|
| |
| VIEW FLIP CONTENT |
| |
| |
| |
| |
| |
| |
| |
| |
-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
就是这样,现在您有了一个包含两个选项卡的tabhost,要添加更多选项卡,只需继续添加更多tabhost即可。当然,您需要更改每个选项卡的文本,并填写您自己的活动,而不是“YourFirstActivity”和“YourSecondActivity”
有关教程,请查看此处:可以将所有选项卡放在不同的活动中。为父活动创建简单布局,如下所示:
-------------------------------------------
| | | |
| T A B | T A B | T A B |
| SELECTED | | |
|-----------------------------------------|
| |
| VIEW FLIP CONTENT |
| |
| |
| |
| |
| |
| |
| |
| |
-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
就是这样,现在您有了一个包含两个选项卡的tabhost,要添加更多选项卡,只需继续添加更多tabhost即可。当然,您需要更改每个选项卡的文本,并填写您自己的活动,而不是“YourFirstActivity”和“YourSecondActivity”
有关教程,请查看以下内容: