Android-如何将列表视图项对齐以左右对齐?

Android-如何将列表视图项对齐以左右对齐?,第1张

概述我试图将图像添加到我的ListView,使其看起来更像一个按钮.我希望图像要小一些,也许是当前的60%.图像在右侧的列中很好地呈现.这是我目前拥有的屏幕:这是我的列表视图xml:<?xmlversion="1.0"encoding="utf-8"?><TextViewxmlns:android="http://schemas.android.com/apkes/a

我试图将图像添加到我的ListVIEw,使其看起来更像一个按钮.我希望图像要小一些,也许是当前的60%.图像在右侧的列中很好地呈现.这是我目前拥有的屏幕:

这是我的列表视图xml:

<?xml version="1.0" enCoding="utf-8"?>  <TextVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_height="fill_parent"    androID:padding="10dp"    androID:textSize="16sp"        androID:layout_wIDth="match_parent"    androID:drawableRight="@drawable/arrow_button"      ></TextVIEw> 

知道我做错了什么吗?

包含此TextVIEw的ListVIEw的定义如下:

需要注意的是,我创建和使用列表的方式是使用listadapter,使用如下代码:

Question q = new Question ();q.setQuestion( "This is a test question and there are more than one" );questions.add(q);adapter = new ArrayAdapter<Question>( this, R.layout.questions_List, questions);setlistadapter(adapter);

谢谢!

解决方法:

有了Frank Sposaro的评论和建议,您将能够正确地定位您的观点.

对于下一个问题,我建议您制作自己的适配器,如下所示:

private class CustomAdapter extends ArrayAdapter<Question> {        private LayoutInflater mInflater;        public CustomAdapter(Context context) {            super(context, R.layout.row);            mInflater = LayoutInflater.from(context);        }        public VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent) {            VIEwHolder holder;            if (convertVIEw == null) {                convertVIEw = mInflater.inflate(R.layout.row, null);                holder = new VIEwHolder();                holder.text = (TextVIEw) convertVIEw.findVIEwByID(R.ID.mTextVIEw);                holder.image = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.mImage);                convertVIEw.setTag(holder);            } else {                holder = (VIEwHolder) convertVIEw.getTag();            }            //Fill the vIEws in your row            holder.text.setText(questions.get(position).getText());            holder.image.setBackground... (questions.get(position).getimage()));            return convertVIEw;        }    }    static class VIEwHolder {        TextVIEw text;        ImageVIEw image;    }

在您的onCreate中:

ListVIEw mListVIEw = (ListVIEw) findVIEwByID(R.ID.mListVIEw);mListVIEw.setAdapter(new CustomAdapter(getApplicationContext(), questions));

带有适配器的ListVIEw的另一个示例可以找到here

总结

以上是内存溢出为你收集整理的Android-如何将列表视图项对齐以左右对齐?全部内容,希望文章能够帮你解决Android-如何将列表视图项对齐以左右对齐?所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1094239.html

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

发表评论

登录后才能评论

评论列表(0条)

保存