0

我明白了,在我的 RelativeLayout 中必须有两个 TextView 和一个 ExpandableListView。经过长时间的交谈,我决定展示图片,以便您了解布局本身的行为。

有快照。第一个是 ExpandableListView 未展开时:

在此处输入图像描述

但是,当我尝试扩展此 ExpandableListView 时,我看到以下内容:

在此处输入图像描述

我们只能看到展开列表的一小部分,其颜色与下一个 TextView 的颜色相同。为什么会这样?我的目标是查看整个展开的 ExpandableListView。

xml的代码:

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="#000000" >

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#00ff00" >

        <TextView
            android:id="@+id/user"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:paddingLeft="3dp"
            android:text="Top User"
            android:textColor="#111111"
            android:background="#eeeeee"
            android:textSize="22dp" />
        <ExpandableListView
            android:id="@+id/elvMain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
        </ExpandableListView>
        <TextView
            android:id="@+id/about"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:text="Bottom About"
            android:textColor="#6f6f6f"
            android:textSize="24dp"
            android:textStyle="bold" />

    </LinearLayout>
</ScrollView>

以及活动的代码:

public class IngredientsActivity extends Activity {


private ArrayList<Ingredient> ingredients;
private Bitmap bitmap;
private final String TAG = "IngredientsActivity";

public void onCreate (Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.ingredients_layout);
    //ingredients = (ArrayList)getIntent().getSerializableExtra("ingredients");
    //bitmap = (Bitmap)getIntent().getParcelableExtra("bitmap");
    prepareIngredients();  //preparing ExpandableListView children
    TextView user = (TextView)findViewById(R.id.user);
    TextView about = (TextView)findViewById(R.id.about);
    user.setText("Albert Einstein");
    about.setText("Albert Einstein (play /ˈælbərt ˈaɪnstaɪn/; German: [ˈalbɐt ˈaɪnʃtaɪn] ( listen); 14 March 1879 – 18 April 1955) was a German theoretical physicist who developed the theory of general relativity, effecting a revolution in physics. For thisfor his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect.[5] The latter was pivotal in establishing quantum theory within physics.");
}
     private void prepareIngredients() {
      SimpleExpandableListAdapter adapter;
      final ExpandableListView list =                                       (ExpandableListView)findViewById(R.id.elvMain);

      ArrayList<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
      Map m  = new HashMap<String, String>();
      m.put("groupName", "Datas");
      groupData.add(m);


      String groupFrom[] = new String[] {"groupName"};

      int groupTo[] = new int[] {R.id.groupname};


     ArrayList<ArrayList<Map<String, String>>> childData = new ArrayList<ArrayList<Map<String, String>>>();
     ArrayList<Map<String, String>> childDataItem = new ArrayList<Map<String, String>>();
     for (Ingredient i : ingredients) {
            Log.d(TAG, "Ingridient: " + i);
            Map<String, String> m1 = new HashMap<String, String>();
            StringBuilder ingredientsString = new StringBuilder();
            String v = i.getValue();
            if (!v.equals("null")) {
                ingredientsString.append("- " + i.getName() + " " + v + i.getType());
            } else {
                ingredientsString.append("- " + i.getName() + " " + i.getType());
            }
            m1.put("levelTwoCat", ingredientsString.toString());
            childDataItem.add(m1);
     }
     childData.add(childDataItem);

     String childFrom[] = new String[] {"levelTwoCat"};
     int childTo[] = new int[] {R.id.ingredients_second_layer_text};

     adapter = new SimpleExpandableListAdapter (
                this,
                groupData,
                R.layout.ingredients_first_layer,
                groupFrom,
                groupTo,
                childData,
                R.layout.ingredients_second_layer,
                childFrom,
                childTo);

     list.setAdapter(adapter);       
}

问题是一样的。如何在此布局中强制 ExpandableListView 展开?现在它没有像它必须的那样扩展。(请参阅顶部的快照)。

4

1 回答 1

0

我认为@AkashG 所说的你的主要问题是你的ListView内部有一个ScrollView. 试着删除你的ScrollView

于 2012-07-20T08:40:32.050 回答