Android 滚动视图内部LinearLayout中的视图列表

Android 滚动视图内部LinearLayout中的视图列表,android,xml,android-layout,Android,Xml,Android Layout,我试图在ScrollView中添加两个列表,最近我读到不应该将ListView放在ScrollView中。所以我决定尝试使用两个LinearLayouts并动态地向它们添加膨胀视图。不幸的是,我看到的只是我用作标题的两个文本视图,而不是线性布局。:/有人能解释一下为什么我的线性布局没有显示出来吗 布局膨胀: ArrayList<JSONObject> sightList = new ArrayList<JSONObject>(); try{ JSONObj

我试图在ScrollView中添加两个列表,最近我读到不应该将ListView放在ScrollView中。所以我决定尝试使用两个LinearLayouts并动态地向它们添加膨胀视图。不幸的是,我看到的只是我用作标题的两个文本视图,而不是线性布局。:/有人能解释一下为什么我的线性布局没有显示出来吗

布局膨胀:

ArrayList<JSONObject> sightList = new ArrayList<JSONObject>();
    try{
    JSONObject obj = new JSONObject(loadJSONFromAsset());
    JSONArray m_jArry = obj.getJSONArray("Locations");

    for (int i = 0; i < m_jArry.length(); i++) 
      {
       JSONObject jo_inside = m_jArry.getJSONObject(i);
       if ("Food & Drink".equals(jo_inside.getString("Section")))
       {
           sightList.add(jo_inside);
       }
      }
    }
    catch (Exception e) {}
    sort(sightList);

    LinearLayout discounts = (LinearLayout) findViewById(R.id.discount_list);
    LinearLayout others = (LinearLayout) findViewById(R.id.other_list);

    for (int i = 0; i < sightList.size(); i++)
    {
        JSONObject j = sightList.get(i);
        try {
            View v = getLayoutInflater().inflate(R.layout.next_list_item, null);
            v.setId(i);
            TextView title = (TextView) v.findViewById(R.id.title);
            TextView subtitle = (TextView) v.findViewById(R.id.subtitle);
            title.setText(j.getString("name"));
            title.setTypeface(montserrat);
            subtitle.setText(j.getString("TypeOfR"));
            subtitle.setTypeface(montserrat);

            if (j.getBoolean("hasDiscount"))
            {
                discounts.addView(v);
            }
            else
            {
                title.setTextColor(Color.BLACK);
                others.addView(v);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
ArrayList sightList=new ArrayList();
试一试{
JSONObject obj=新的JSONObject(loadJSONFromAsset());
JSONArray m_jArry=obj.getJSONArray(“位置”);
for(int i=0;i
活动布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView 
    android:id="@+id/featured"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:contentDescription="@string/featured"
    android:src="@drawable/bandus"
    android:layout_alignParentTop="true"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"/>

<ScrollView 
    android:id="@+id/next_info_holder"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/featured">

    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <TextView 
        android:id="@+id/discounts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp"
        android:paddingTop="3dp"
        android:paddingBottom="3dp"
        android:background="@color/list_header"
        android:text="@string/food"
        android:textColor="@color/header_text"
        android:textSize="14sp"/>

    <LinearLayout 
        android:id="@+id/discount_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/discounts"
        android:orientation="vertical"/>

    <TextView 
        android:id="@+id/others"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Other Food and Drink"
        android:layout_below="@id/discount_list"
        android:paddingLeft="8dp"
        android:paddingTop="3dp"
        android:paddingBottom="3dp"
        android:background="@color/list_header"
        android:textColor="@color/header_text"
        android:textSize="14sp"/>

    <LinearLayout 
        android:id="@+id/other_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/discounts"
        android:orientation="vertical"/>

    </RelativeLayout>

</ScrollView>

</RelativeLayout>

清单项目:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp" >

<RelativeLayout 
    android:id="@+id/title_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_centerVertical="true">

    <TextView 
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/badass_blue"
        android:textSize="17sp"/>

    <TextView 
        android:id="@+id/subtitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/list_header"
        android:textSize="12sp"
        android:layout_below="@id/title"/>

</RelativeLayout>

<ImageView 
    android:id="@+id/divider"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:src="@drawable/divider"
    android:contentDescription="@string/divider"/>

<ImageView 
    android:id="@+id/details"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/bluearrow"
    android:contentDescription="@string/arrow"
    android:layout_marginRight="20dp"/>

</RelativeLayout>


谢谢你的帮助(很抱歉发了这么长的帖子):

你确定没有收到任何
JSONException
s吗?你想得到什么?也许你想要一个包含部分的列表视图?那可以,你能有一个包含多个标题的列表视图吗?LeiNaD_87,谢谢你的建议,如果你把它作为一个答案添加,我会接受的