本文介绍了如何显示的行数固定在ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的只显示5行的的ListView ,其中剩下的应该是滚动。到目前为止我已经尝试过这种

I want to display only 5 rows in a ListView and rest of them should be scrollable.So far i have tried this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/txtFilename"
        android:layout_width="375dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />

    <ListView
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarSize="2dp"
        android:

        />



     <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/gray"
        android:padding="5dp" >

        <Button
            android:id="@+id/btnOk"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="OK"/>

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="CANCEL"/>
    </LinearLayout>


</LinearLayout>

的Java code

public class MainActivity extends Activity {

    private ListView list1;

    private String array[] = { "Iphone", "Tutorials", "Gallery", "Android",

    "item 1", "item 2", "item3", "item 4" };
    @SuppressWarnings("unchecked")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        //parentLayout.add(childLayout);

        setContentView(R.layout.activity_main);
        list1 = (ListView) findViewById(R.id.ListView01);

        // By using setAdpater method in listview we an add string array in

        // list.

        list1.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, array));

    }

有任何想法如何实现它

have any idea how to achieve it

推荐答案

在这里,我只是修改你的布局刚检查出来!!

Here i am Just Modifying Your Layout just check it out!!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/txtFilename"
        android:layout_width="375dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" />
<LinearLayout
         android:layout_width="fill_parent"
         android:layout_height="300dip">
    <ListView
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbarSize="2dp"


        />


</LinearLayout>
     <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/gray"
        android:padding="5dp" >

        <Button
            android:id="@+id/btnOk"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="OK"/>

        <Button
            android:id="@+id/btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="CANCEL"/>
    </LinearLayout>


</LinearLayout>

这篇关于如何显示的行数固定在ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 23:45
查看更多