在 AsyncTask 之后更改视图高度(并使其可滚动)



我有一个片段选项卡实现,其中包含选项卡内容,FrameLayout如下:

<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:id="@+id/tab_content_wrapper">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>
        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_weight="0"
            android:showDividers="none"
            android:background="#434343"/>
    </LinearLayout>
</TabHost>

然后在真实内容中,我可以添加ListView并且它是可滚动的。但是,当我想有一个RelativeLayout来具有固定高度的内容并在其下方添加ListView时,就会发生麻烦。它具有以下资源布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/some_content_with_listview"
    android:orientation="vertical"
    android:background="#ffffff">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:gravity="top"
        android:paddingLeft="10dp"
        android:paddingTop="7dp"
        android:paddingRight="10dp"
        android:id="@+id/pre_list_view_content"
        android:layout_marginLeft="7dp"
        android:layout_marginRight="7dp">
        ...
    </RelativeLayout>
    <ListView
        android:id="@+id/my_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:smoothScrollbar="true">
    </ListView>
</LinearLayout>

AsyncTask 之后,my_list_view填充了项目,并在非常短的可滚动ListView中显示。我似乎无法在没有滚动的情况下使LinearLayout更高以容纳整个ListView。所以澄清一下,我想使ListView不可滚动,而是使LinearLayout在realtabcontent(FrameLayout)中可滚动

提前谢谢!

您可以为相对布局创建不同的布局:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:gravity="top"
        android:paddingLeft="10dp"
        android:paddingTop="7dp"
        android:paddingRight="10dp"
        android:id="@+id/pre_list_view_content"
        android:layout_marginLeft="7dp"
        android:layout_marginRight="7dp">
        ...
    </RelativeLayout>

并将其作为标题添加到列表视图中。

 //inflate this layout and get view object
lvMyListView.addHeaderView(view,null,false);

您可以查看有关添加标题的更多信息

http://www.vogella.com/tutorials/AndroidListView/article.html#miscellaneous_headerfooter

最新更新