4

を使用しSimpleCursorAdapterて単一のを表示していますCheckedTextView。私はこれがとを使用して最もよく行われることを知っていsimple_list_item_multiple_choiceますandroid.R.id.text1

adapter = new SimpleCursorAdapter(getApplicationContext(), 
              android.R.layout.simple_list_item_multiple_choice, rules, 
              new String[]{Constants.KEY_RULE}, new int[]{android.R.id.text1});

からのテキストKEY_RULEが2行を超える場合、androidは折り返さず、代わりに非表示にします。独自のアダプターを実装しなくても、これを簡単に回避できますか?

以下の私のxmlコードを見つけてください:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TextView android:id="@+id/header" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/rule_selection_for_revision_list_title"
        android:padding="4dip" android:background="#000000" android:textColor="#ffffff" android:textStyle="bold" />

  <ListView
    android:id="@android:id/list"
     android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_weight="1.0" />

    <TextView android:textSize="18sp" android:textStyle="bold"
        android:id="@id/android:empty" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:gravity="center_vertical|center_horizontal"
        android:text="There are no rules to consider." />

</LinearLayout>

少なくともフォントサイズを2行に収まるように縮小する方法はありますか?

4

2 に答える 2

2

いくつかのオプションがあります。

リスト内のアイテムのカスタムレイアウトを定義できます。これにより、アイテムのUIを完全にカスタマイズできます。詳細については、リストビューチュートリアルを参照してください。

他のアプローチは、標準のアイテムレイアウトを使用したいが、その中の1つの小さなものだけを修正する場合に使用できます。アダプタを拡張し、getView機能のビューを変更できます。次に例を示します。

class MySimpleCursorAdapter extends SimpleCursorAdapter
{
    public MySimpleCursorAdapter(Context ctx, int layout, 
                                 Cursor cursor, String [] from, int [] to)
    {
        super(ctx, layout, cursor, from, to);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View view = super.getView(position, convertView, parent);

        TextView textView = (TextView)view.findViewById(android.R.id.text1);

        //You can increase number of lines in the text view
        textView.setMaxLines(5);

        LayoutParams params = textView.getLayoutParams();
        if(params.height > 0)
        {
            int height = params.height;
            params.height = LayoutParams.WRAP_CONTENT;                              
            textView.setLayoutParams(params);
            textView.setMinHeight(height);
        }

        //Or you can make your font smaller
        textView.setTextSize(customTextSize);

        //or whatever you like, even apply new custom style
        //...

        return view;
    }   

}

おそらく最初のアプローチ(カスタムレイアウト)を選択する必要がありますが、2番目のアプローチも実行可能な場合があります。

于 2011-06-03T11:06:40.190 に答える
0

カスタムアダプタを実装する必要はありません。リストアイテムのカスタムレイアウトを定義し、それをの代わりにアダプタに渡すだけですandroid.R.layout.simple_list_item_multiple_choice

Androidソース(コンピューターにSDKが付属しています)を検索して、元のsimple_list_item_multiple_choiceレイアウトがどのように見えるかを調べ、ニーズに適合させることができます。

于 2011-06-03T11:06:08.750 に答える