2017-10-25 11 views
1

대화 상자의 내용이 동적 인 사용자 정의 대화 상자를 만들려고합니다. 따라서 대화 상자에보기를 전달하면 해당보기가 대화 상자에 추가됩니다. 현재 사용자 정의보기와 해당보기의 너비와 높이가 0임을 나타내는 코드는 그려지지 않습니다.Android - 사용자 정의 대화 상자

다른 사용자 정의와 함께 Application 클래스를 통해 사용자 정의보기를 전달합니다.

public class Spinner extends LinearLayout 
    { 
     public Spinner(Context context) { 
      super(context); 
      init(context); 
     } 

     public Spinner(Context context, @Nullable AttributeSet attrs) { 
      super(context, attrs); 
      init(context); 
     } 

     public Spinner(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 
      super(context, attrs, defStyleAttr); 
      init(context); 
     } 

     private void init(Context context) { 

      View aView = View.inflate(context, R.layout.loading_activity, null); 
      ImageView logoImage = (ImageView) aView.findViewById(R.id.loading_image); 
      logoImage.setImageResource(R.drawable.loading_chicken2); 
     } 
    } 

답변

1

사용자 정의보기 스피너 아무것도 팽창 레이아웃 'R.layout의 원인이 그려하지 않습니다 Heres는

public class LoadingActivity extends Dialog 
    { 
     private LoadingActivity(Context a) { 
      super(a, android.R.style.Theme); 
     } 

     public static LoadingActivity show(Context context) { 

      LoadingActivity checkerLoader = new LoadingActivity(context); 

      View currentView = View.inflate(context, R.layout.loading_activity, null); 
      FrameLayout linearLayout = (FrameLayout) currentView.findViewById(R.id.circular_progress_bar); 
      RelativeLayout viewLayout = (RelativeLayout) currentView.findViewById(R.id.view_layout); 

      if (DataManager.getInstance().getAppConfigurations().getLoadingActivity() != null) { 
       View loadingView = DataManager.getInstance().getAppConfigurations().getLoadingActivity(); 
       loadingView.setBackgroundColor(Color.RED); 
       loadingView.invalidate(); 
       if(loadingView.getParent()!=null) { 
        ((ViewGroup) loadingView.getParent()).removeView(loadingView); 
       } 
       viewLayout.addView(loadingView); 
      } 

      checkerLoader.requestWindowFeature(Window.FEATURE_NO_TITLE); //before 
      checkerLoader.setContentView(currentView); 

      checkerLoader.setCancelable(false); 
      checkerLoader.getWindow().getAttributes().gravity = Gravity.CENTER; 

      WindowManager.LayoutParams lp = checkerLoader.getWindow().getAttributes(); 
      lp.dimAmount=0.2f; 

      checkerLoader.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
      checkerLoader.getWindow().setAttributes(lp); 
      checkerLoader.show(); 

      return checkerLoader; 
     } 
    } 

내 사용자 정의보기의 예 :

여기 내 대화 상자 클래스입니다. loading_activity '는 상위 항목에 추가되지 않습니다.

View aView = View.inflate(context, R.layout.loading_activity, null); 

에 변경 :

View aView = View.inflate(context, R.layout.loading_activity, this); 

도움이 될