选项卡布局内的Android可滚动视图

时间:2012-08-01 01:56:08

标签: android android-layout scrollview expandablelistview

我目前在Android布局的选项卡中有可滚动视图的问题。视图在选项卡下方滚过,而没有在选项卡布局中实现的可滚动视图,如下所示。

http://i46.tinypic.com/2ccmp0w.png

当我在选项卡式布局中放置一个可滚动视图时,它会显示一个小的可滚动视图,该视图显示错误且无法使用。如下所示。

http://tinypic.com/r/29ej2ft/6

标签主机的代码位于

之下
<?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">
<RelativeLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:padding="5dp" />
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />        
</RelativeLayout>
</TabHost>

这是实现滚动视图的选项卡的代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/todayScroll" 
android:layout_height="wrap_content"
android:layout_width="fill_parent" >

<LinearLayout 
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"      
    android:orientation="vertical" >

            <ExpandableListView
                android:id="@+id/ExpList"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:groupIndicator="@null" />   

</LinearLayout>
</ScrollView>

如何让内容正确滚动而不妨碍选项卡的任何想法将非常感谢:)谢谢。

我已经尝试了几次,但它开始变得非常令人沮丧。

编辑: 这是TabHostActivity文件。

public class TabbedMainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_main);

    TabHost tabHost = getTabHost();

    // Tab for todays meals
    TabSpec todaysSpec = tabHost.newTabSpec("Todays");
    //you could set icon here as well as title
    todaysSpec.setIndicator("Todays");
    Intent todaysIntent = new Intent(this, TodaysMealsActivity.class);
    todaysSpec.setContent(todaysIntent);

    // Tab for future meals
    TabSpec futureSpec = tabHost.newTabSpec("Future");
    futureSpec.setIndicator("Future");
    Intent futureIntent = new Intent(this, FutureMealsActivity.class);
    futureSpec.setContent(futureIntent);

    // Tab for comments
    TabSpec commentsSpec = tabHost.newTabSpec("Comments");
    commentsSpec.setIndicator("Feedback");
    Intent commentsIntent = new Intent(this, CommentsActivity.class);
    commentsSpec.setContent(commentsIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(todaysSpec); // Adding todays tab
    tabHost.addTab(futureSpec); // Adding future tab
    tabHost.addTab(commentsSpec); // Adding comments tab
}
}

干杯, Rmplanner

1 个答案:

答案 0 :(得分:0)

从评论中修改:找到了另一种解决方案(OP使用的解决方案)here

android:layout_height="fill_parent"上使用ScrollView。 (或者,由于不推荐使用fill_parent,请使用android:layout_height="match_parent"。)

首先,移除您的ScrollView,然后将RelativeLayout替换为:

<RelativeLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_above="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
相关问题