Android标签意图,通过标签进行布局剪裁

时间:2011-11-22 14:06:17

标签: android android-layout

我正在使用TabLayout创建一个应用程序,并且在使用Intents加载不同的类时显示有问题。

我尝试使用此处所见的Android开发指南中介绍的方法创建它

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

然而我遇到的问题是,我希望应用程序底部的选项卡而不是我所做的顶部。问题是屏幕上没有足够的空间来查看整个应用程序,因此当我单击一个新选项卡并加载其布局时,它会直接通过选项卡。我尝试添加ScrollView但它似乎不起作用。

关于如何解决这个问题的任何建议,所以当我加载一个屏幕时,我可以在页面上下滚动,我的标签总是出现在底部而没有我的标签夹在我的标签中。

非常感谢任何帮助

我的main.xml代码是

<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" android:background="#92c223">

<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:padding="5dp" />

</LinearLayout>

<TabWidget android:id="@android:id/tabs"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_gravity="bottom" />
</TabHost>

我用来在java中的选项卡之间交换的代码是

intent = new Intent().setClass(this, tag.class); 
    spec = tabHost.newTabSpec("tag1")
            .setIndicator("tag1", res.getDrawable(R.drawable.icon))
            .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, tag2.class);
    spec = tabHost.newTabSpec("tag2")
            .setIndicator("tag2", res.getDrawable(R.drawable.icon2))
            .setContent(intent);
    tabHost.addTab(spec);

1 个答案:

答案 0 :(得分:1)

试试这个

<?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="wrap_content"
            android:padding="5dp"
            android:layout_weight="1"/>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>

    </LinearLayout>

</TabHost>

不同之处在于FrameLayout,高度设置为wrap_content,其中你的设置为fill_parent。此外,他在FrameLayout上应用layout_weight = 1,在TabWidget上应用layout_weight = 0。

取自here