调整FastScroll警示对话框大小

5

我希望在我的历史记录列表中使用FastScroll,并使用日期作为分组的依据,但警示对话框(显示联系人字母)不会根据文本大小自动调整大小(我想在那里显示月份和日期)。

如何调整它的大小?


有进展吗?你试过我的建议了吗? - gary
2个回答

1

可能只是在AlertDialog类中使用setView这样简单的事情吗?(以及对.xml文件进行一些编辑)。首先,我从这里获取了有关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

这里是SDK的示例代码(AlertDialogSamples.java),其中使用了setView

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" />

希望它有所帮助。


这怎么应用到FastScroll上?回答晚了很抱歉。 - Denis Palnitsky

1
我的解决方案。 我们禁用了内置的快速滚动功能,并使用this代码进行了微小的更改。变量 mOverlaySize 负责部分警报的大小。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接