Android的 - 如何排列列表视图项目被很好地隔开的左,右对齐?很好、视图、排列、项目

2023-09-05 04:19:35 作者:壮志凌云

我试图将图像添加到我的ListView,使它看起来更像一个按钮。我想图像要小一点,也许60%的电流。并且图像很好地LIGN向上的右侧一列。这里是什么,我现在有一个画面:

I am trying to add an image to my ListView to make it look more like a button. I would like the images to be a little smaller, maybe 60% of current. And the images to lign up nicely on the right in a column. Here is a screen of what I currently have:

和这里是我的列表视图中的xml:

and here is my list view 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> 

任何想法,我在做什么错误?

any idea what I am doing incorrectly?

这包含此TextView的ListView控件的定义是这样的:

The ListView that contains this TextView is defined like this:

一注,该方式创建和我列出的工作是与ListAdapter,用code是这样的:

One note, the way I create and work with my Lists is with the ListAdapter, using code like this:

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);

谢谢!

推荐答案

通过评论和建议弗兰克Sposaro了,你就可以正确地定位你的看法。

With the comment and advice that Frank Sposaro gave, you will be able to position your views correctly.

有关你的下一个问题,我建议你做你自己的适配器与此类似:

For your next problem, I advice you to make your own adapter similar to this:

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:

In your onCreate:

ListView mListView = (ListView) findViewById(R.id.mListView);
mListView.setAdapter(new CustomAdapter(getApplicationContext(), questions));

这里

再比如用于与适配器一个ListView可以发现

Another example for a ListView with an Adapter can be found here