android– 是否无法向ScrollView添加多个视图?

android– 是否无法向ScrollView添加多个视图?,第1张

概述如果是这样,似乎ScrollView相当蹩脚(令人怀疑)或者还有其他一些方法可以做到这一点.这是我的代码.它被轰炸的地方(第二次通过循环,即)被评论.publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.ondemanda

如果是这样,似乎ScrollVIEw相当蹩脚(令人怀疑)或者还有其他一些方法可以做到这一点.这是我的代码.它被轰炸的地方(第二次通过循环,即)被评论.

public voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.ondemandandautomatic_dynamicauthorize);    ScrollVIEw svh = (ScrollVIEw) findVIEwByID(R.ID.scrollVIEwHost);    // Contacts data snippet adapted from    // http://saigeethamn.blogspot.com/2011/05/contacts-API-20-and-above-androID.HTML    ContentResolver cr = getContentResolver();    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,            null, null, null);    if (cur.getCount() > 0) {        while (cur.movetoNext()) {            String ID = cur.getString(cur                    .getColumnIndex(ContactsContract.Contacts._ID));            String name = cur                    .getString(cur                            .getColumnIndex(ContactsContract.Contacts.disPLAY_name));            // Create a linear Layout for each contact?            linearLayout llay = new linearLayout(this);            llay.setorIEntation(linearLayout.HORIZONTAL);            linearLayout.LayoutParams llp = new LayoutParams(                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);            llp.weight = 1.0f;            CheckBox cbondemand = new CheckBox(getApplicationContext());            cbondemand.setTag(ID);            cbondemand.setLayoutParams(llp);            llay.addVIEw(cbondemand);            CheckBox cbTime = new CheckBox(getApplicationContext());            cbondemand.setTag(ID);            cbTime.setLayoutParams(llp);            llay.addVIEw(cbTime);            CheckBox cbSpace = new CheckBox(getApplicationContext());            cbondemand.setTag(ID);            cbSpace.setLayoutParams(llp);            llay.addVIEw(cbSpace);            TextVIEw tv = new TextVIEw(getApplicationContext());            tv.setTag(ID);            tv.setText(name);            tv.setLayoutParams(llp);            llay.addVIEw(tv);            svh.addVIEw(llay); // it transports me to Eclipse's DeBUG perspective when I hit this line the SECOND time around.            // One cat on stackOverflow saID to do this, another saID it            // would be unnecessary            svh.invalIDate();        }    }}

解决方法:

你可以做两件事来解决这个问题.

1)使ScrollVIEw的唯一子项成为垂直linearLayout,并将所有子项添加到linearLayout而不是ScrollVIEw.

2)一个更好的选择是使用ListVIEw(可能是使用ScrollVIEw内部的linearLayout实现的).

总结

以上是内存溢出为你收集整理的android – 是否无法向ScrollView添加多个视图?全部内容,希望文章能够帮你解决android – 是否无法向ScrollView添加多个视图?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1120115.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存