2

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

ありがとう!

4

2 に答える 2

4

ああ。複合ドローアブルを使用して正しいことをしています。複合ドローアブルの間隔を広げるためのより良い方法があるかどうかはわかりませんが、これが機能することはわかっています。

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

<TextView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:padding="10dp"
    android:textSize="16sp"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true" />

<View
    android:layout_height="64dip"
    android:layout_width="64dip"
    android:background="@drawable/arrow_button"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true" />

</RelativeLayout>

基本的には、alignparent right and left を使用して指摘するだけです。余白やパディングを追加したい場合があります。また、要素を垂直方向に中央揃えにしてください。

于 2012-07-18T03:26:25.657 に答える
1

フランク・スポサロからのコメントとアドバイスにより、あなたは自分の意見を正しく位置づけることができるでしょう。

次の問題については、次のような独自のアダプターを作成することをお勧めします。

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の別の例は、ここにあります。

于 2012-07-24T15:16:11.313 に答える