fill_parent与ListFragement

时间:2011-08-24 20:48:50

标签: android android-layout android-widget android-fragments

我在让ListFragment垂直填充屏幕时遇到问题。它在数据加载时填充正常,但是一旦我调用setListShown(true),它就会收缩到wrap_content。我更改了fragmentContainer的背景并验证它也在缩小。我正在开发2.3.3手机。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if(savedInstanceState == null){
            Queues qs = new Queues();
            fragmentTransaction.add(R.id.fragmentContainer, qs);
            fragmentTransaction.commit();
    }
}

<LinearLayout android:id="@+id/fragmentContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

编辑: 这是完整的布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout android:id="@+id/queueHeader"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:background="@drawable/header_gradient"
        android:gravity="center" >
        <TextView android:id="@+id/queueHeaderText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:textSize="14pt"
            android:text="Queues" />
    </LinearLayout>
    <ImageView
        android:layout_width="48dip"
        android:layout_height="48dip"
        android:layout_marginTop="-50dip"
        android:layout_marginLeft="8dip"
        android:src="@drawable/inin48" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#CCFFFFFF" >
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_weight="1" >
            <ImageView android:id="@+id/navCallback"
                android:layout_width="32dip"
                android:layout_height="32dip"
                android:layout_margin="6dip"
                android:src="@drawable/phone32" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FF000000"
                android:text="Callbacks" />
        </LinearLayout>
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_weight="1" >
            <ImageView android:id="@+id/navNews"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="6dip"
                android:src="@drawable/news32" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FF000000"
                android:text="News" />
        </LinearLayout>
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_weight="1" >
            <ImageView android:id="@+id/navAbout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="6dip"
                android:src="@drawable/about32" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FF000000"
                android:text="About" />
        </LinearLayout>
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:layout_weight="1" >
            <ImageView android:id="@+id/navSettings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="6dip"
                android:src="@drawable/settings32" />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FF000000"
                android:text="Settings" />
        </LinearLayout>
    </LinearLayout>
    <FrameLayout android:id="@+id/fragmentContainer"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

0 个答案:

没有答案