2011-08-30 58 views
0

我有一個自定義對話框。我用下面的代碼在「onCreateDialog」的方法來創建它:如何永久旋轉我的自定義AlertDialog?

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

你只需要在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);  
    } 
} 
+0

非常感謝。這很有幫助。 – breceivemail