这是我的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" android:background="#E7F7FF" android:gravity="top">
<!-- Header text here -->
<TextView />
<!-- Scrollable layout -->
<ScrollView >
<RelativeLayout android:layout_height="fill_parent" android:layout_marginTop="5dip" android:layout_width="fill_parent">
<LinearLayout >
<ImageView />
</LinearLayout>
<LinearLayout >
<TextView />
<TextView />
<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView android:id="@+id/contact_number_list_view" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent"
android:layout_marginTop="3dp" android:layout_marginBottom="1dp" android:layout_marginRight="5dip" android:clickable="true"
android:cacheColorHint="#00000000" android:divider="@android:color/transparent" android:dividerHeight="2dip" android:fastScrollEnabled="true"
android:fadeScrollbars="true" android:listSelector="@drawable/rounded_corner_item_selecter" android:layout_gravity="top"></ListView>
<TextView />
</FrameLayout>
</LinearLayout>
<!-- Show tags details layout -->
<LinearLayout >
<TableLayout >
</TableLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
<!-- Now button layouts here -->
<LinearLayout >
<Button />
<Button/>
<Button />
</LinearLayout>
</RelativeLayout>
我想将列表视图扩展为其中的数据量。但它的规模并没有扩大。为什么?
答案 0 :(得分:1)
正如程序员所解释的那样,来自GoogleIo的这个video中的listView从未将ListView放在滚动视图中。如果列表不应滚动,请使用类似线性布局的ViewGroup,并在代码的循环中将所有项添加到此ViewGroup。如果希望整行可以单击,则必须使用另一个ViewGroup作为每行的根节点,并将OnClickListener添加到此视图。
所以只需将您的ListView
替换为LinearLayout
作为
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linear_layout_which_is_present_at_place_of_list_view"
android:orientation="vertical"/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
并且让您使用两个TextView作为列表视图的自定义行。所以自定义行视图将是 row_view_layout.xml为
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:clickable="true"
android:id="@+id/row_view_layout_text1"
android:layout_height="wrap_content" />
<TextView android:id="@+id/row_view_layout_text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"/>
</LinearLayout>
示例代码:
//Let you were using two TextView as custom row of list view.
LinearLayout list = (LinearLayout)findViewById(R.id.linear_layout_which_is_present_at_place_of_list_view);
LayoutInflater inflater = LayoutInflater.from(context);
list.removeAllViews(); //Remove previously created views
for(String row : getAllRow()) {
View vi = inflater.inflate(R.layout.row_view_layout, null);
textOne = (TextView) vi.findViewById(R.id.row_view_layout_text1);
textTwo = (TextView) vi.findViewById(R.id.row_view_layout_text2);
final String t1 = row.getFirstValue();
final String t2 = row.getSecondValue();
textOne.setText(t1);
textTwo.setText(t2);
//Set listener for both text views
textOne.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(context, "You clicked on : " + t1 , Toast.LENGTH_SHORT).show();
}
});
textTwo.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(context, "You clicked on : " + t2 , Toast.LENGTH_SHORT).show();
}
});
//Add view
list.addView(vi);
}
希望这会有所帮助。
快乐的编码。
答案 1 :(得分:0)
<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView android:id="@+id/contact_number_list_view" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="fill_parent"
android:layout_marginTop="3dp" android:layout_marginBottom="1dp" android:layout_marginRight="5dip" android:clickable="true"
android:cacheColorHint="#00000000" android:divider="@android:color/transparent" android:dividerHeight="2dip" android:fastScrollEnabled="true"
android:fadeScrollbars="true" android:listSelector="@drawable/rounded_corner_item_selecter" android:layout_gravity="top">
//HERE PUT THE ITEM VIEWS ELEMENTS OF THE LISTIVIEW
</ListView>
我无法看到可能导致您出现问题的其他任何内容......
答案 2 :(得分:0)
设置ScrollView
的宽度和高度
像这样:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Contents -->
</ScrollView>