如何永久旋转自定义AlertDialog?

时间:2011-08-30 10:34:35

标签: android rotation alertdialog

我有一个自定义对话框。我使用以下代码在“onCreateDialog”方法中创建它:

Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this,
            android.R.style.Theme_Light_NoTitleBar_Fullscreen));

    LayoutInflater inflater = LayoutInflater.from(this);
    final View productsView = inflater.inflate(
            R.layout.dialog_photo_gallery,
            null);
    builder.setView(productsView);
    galProducts = (Gallery) productsView.findViewById(R.id.galProducts);
    ...

我使用link创建了支持旋转的自定义LinearLayout。

我想使用我的自定义LinearLayout类并将资源布局设置为它?我不想在源代码中动态声明我的控件。我想做这样的事情:

RotateLinearLayout myLayout= new RotateLinearLayout(this);
myLayout.setResourceView(R.layout.dialog_photo_gallery);

我该怎么做?

如何同时使用AlertDialog.Builder和我的RotateLinearLayout?

1 个答案:

答案 0 :(得分:1)

您只需将R.layout.dialog_photo_gallery中描述的控件包装到您的RotateLinearLayout

类似的东西:

<com.xxx.RotateLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                       android:layout_width="fill_parent"
                       android:layout_height="fill_parent">
 <Gallery android:id="@+id/galProducts
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"/>
</com.xxx.RotateLinearLayout>

然后:

public class MyDialog extends AlertDialog {
    public MyDialog(Context context) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.dialog_photo_gallery, null);
        setView(view);
        galProducts = (Gallery) view.findViewById(R.id.galProducts);       
    }
}