我想在历史记录列表中使用FastScroll,并在部分中使用日期,但是警报对话框(在联系人中显示字母)无法适应文本的大小(我想在其中显示月份和日期)。

如何调整尺寸?

最佳答案

就像在AlertDialog类中使用setView一样简单吗? (以及对.xml的一些编辑)。首先,我从here获取了有关setView的信息。

public void setView (View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom)

Set the view to display in that dialog, specifying the spacing to appear around that view.
Parameters:
view    The view to show in the content area of the dialog
viewSpacingLeft Extra space to appear to the left of view
viewSpacingTop  Extra space to appear above view
viewSpacingRight    Extra space to appear to the right of view
viewSpacingBottom   Extra space to appear below view

这是一些使用setView的SDK的示例代码(AlertDialogSamples.java)。
case DIALOG_TEXT_ENTRY:
            // This example shows how to add a custom layout to an AlertDialog
            LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.alert_dialog_text_entry)
                .setView(textEntryView)
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked OK so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                })
                .create();
        }
        return null;

最后,一些xml文件看起来像在文本(alert_dialog_text_entry.xml)周围添加了空白。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/username_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:text="@string/alert_dialog_username"
        android:gravity="left"
        android:textAppearance="?android:attr/textAppearanceMedium" />

希望能帮助到你。

关于android - 调整FastScroll警报对话框的大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3531398/

10-10 01:52