我试图在ScrollView中添加两个列表,我最近读到你不应该将ListView放在ScrollView中。所以我决定尝试使用两个LinearLayouts并动态地为它们添加膨胀的视图。不幸的是,我所看到的是我用作标题但没有线性布局的两种文字视图。 :/有人可以解释为什么我的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();
}
}
活动布局:
<?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>
感谢您的帮助(对于长篇文章感到抱歉):)