片段内的ListView无法滚动

时间:2013-01-28 17:59:42

标签: android android-fragments

我有以下布局:enter image description here 黄色背景是列表项,以片段形式存储。

以下是代码im mainActivity:

<fragment android:layout_width="140dp" 
          android:layout_height="100dp" 
          android:layout_below="@+id/block" 
          class="fragments.Demo"/>

片段代码:

public class Demo extends ListFragment{

 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" };

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity().getApplicationContext(), R.layout.list_item_bank, R.id.list_item_bank_name, values);
    setListAdapter(adapter);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.transaction_list_fragment, null);
}
}

R.layout.list_item_bank:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="#ffee00"
         android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

        <TextView android:id="@+id/list_item_bank_name"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="center_vertical"
                 android:layout_marginLeft="10dp"
                 android:text=""
                 android:textColor="@color/abs__primary_text_holo_light"
                 android:textSize="18sp">
        </TextView>
</LinearLayout>

问题是:我无法从主要活动滚动列表视图。怎么了?

1 个答案:

答案 0 :(得分:0)

whooops!在我看来,我发现了这个问题。 我的ListFragment位于ScrollView中。如果我用LinearLayout替换scrollView一切正常!