繁体   English   中英

Android ListActivity Scrollview如何获取要滚动的列表

[英]Android ListActivity Scrollview How to get a list to scroll

我正在浏览http://www.vogella.de/articles/AndroidListView/article.html上的教程,学习如何使用ListActivity。 我试图让列表滚动,但后来意识到你不能在布局文件中使用scrollview来实现这一点。 谷歌搜索后,我意识到android不允许这样,但我找不到一个似乎可以解释如何使滚动发生的答案。

代码如下:

public class MyListActivityActivity extends ListActivity {
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" , "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2"  };
    /*LayoutInflater factory = getLayoutInflater();
    LinearLayout footer = 
            (LinearLayout) factory.inflate(R.layout.main, null);
     getListView().addFooterView(footer); */


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.rowlayout, R.id.label, values);
    setListAdapter(adapter);
}

    protected void onListItemClick(ListView l, View v, int position, long id) {
    String item = (String) getListAdapter().getItem(position);
    Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}

// xml文件:

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

<ImageView
    android:id="@+id/icon"
    android:layout_width="22px"
    android:layout_height="22px"
    android:layout_marginLeft="4px"
    android:layout_marginRight="10px"
    android:layout_marginTop="4px"
    android:src="@drawable/ic_launcher" >
</ImageView>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:textSize="20px" >
</TextView>

</LinearLayout>

目前,放入数组的值越多,列表就越小,以确保它适合屏幕。 我希望文本保持相同的大小,让它成为我可以滚动的长列表。

我已经阅读过有关addHeader和addFooter的内容,它可以实现滚动。 但有人可以向我解释或引导我找到有关如何实现这一点的更多信息的来源吗?

我很感激任何意见。 谢谢

ListView本身就是一个滚动小部件,所以它不能在ScrollView

您不需要额外的ScrollView。 ListActivity或者确切地说ListView在默认情况下是可滚动的,如果有更多项目要绘制,那么空间可用。

顺便说一句,应该避免ScrollViews和ListViews的组合,需要考虑几个问题,你也不需要它来解决问题。

列表视图它是自动滚动。 如果你想设置滚动布局,你可以使用这段代码这对你有用。

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lwidget36"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/lwidget35"
android:background="#000321"
android:overScrollMode="never" >

<LinearLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<ImageView
android:id="@+id/icon"
android:layout_width="22px"
android:layout_height="22px"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:layout_marginTop="4px"
android:src="@drawable/ic_launcher" >
</ImageView>

<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="20px" >
</TextView>

</LinearLayout>
</ScrollView>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM