2012-11-16 3 views
1

에뮬레이터에서 정상적으로 보이지만 기기에서 이상하게 보이는 Alertdialog를 생성하여 표시합니다.Android Alertdialog의 크기는 Emultator와 Device에서 서로 다릅니다.

이것은 에뮬레이터에서와 같은 모습입니다 :이 코드는

enter image description here

입니다 :

enter image description here

이것은 장치에서 같은 모습입니다 대화 상자를 표시하기 위해 실행 중입니다.

AlertDialog.Builder builder; 
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 


    View layout = inflater.inflate(R.layout.popup_contact, (ViewGroup) findViewById(R.id.ppc_llContact)); 
    tbMissatge = (EditText) layout.findViewById(R.id.ppc_tbMissatge); 
    builder = new AlertDialog.Builder(this); 


    builder.setView(layout); 
    ppEnviarMsg = builder.create(); 


    btEnviar = (Button) layout.findViewById(R.id.ppc_btEnviar); 
    btEnviar.setOnClickListener(this); 

    ppEnviarMsg.show(); 


    ppEnviarMsg.getWindow().getAttributes().gravity = Gravity.CENTER; 

그리고 여기에 팝업의 레이아웃 :

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/ppc_llContact" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#414145" 
     android:orientation="vertical" 
     android:gravity="center"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="#ffffff" 
      android:text="@string/ppc_lbContact" 
      android:layout_margin="4dp"/> 

     <EditText 
      android:id="@+id/ppc_tbMissatge" 
      android:hint="@string/ppc_tooltipContact" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dp" 
      android:inputType="textMultiLine" 
      android:gravity="top" 
      android:lines="5"> 
     </EditText> 

     <Button android:id="@+id/ppc_btEnviar" 
      android:text="@string/ppc_btEnviar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:paddingLeft="20dp" 
      android:paddingRight="20dp" 
      android:layout_marginTop="10dp"/> 

    </LinearLayout> 

은 그것이 어쩌면 감각과 관련이있을 수 있을까요? 내 장치는 ICS 및 Sense를 실행하는 HTC Desrie S입니다. 단서가 있습니까?

도와 주셔서 감사합니다.

+2

또한 ICS 에뮬레이터에서 실행을 시도 할 수 있습니다 :

View layout = inflater.inflate(R.layout.popup_contact, null); 

또 다른 옵션은 강제로 대화의이 방법으로 크기를 설정하는 것입니다. 스크린 샷의 에뮬레이터는 2.3과 같이 보입니다. – Ivan

+0

dialogfragment를 사용해보고 동작 방식을 확인하는 것이 좋습니다. – Warpzit

+0

이미지를 편집 해 주셔서 감사합니다. 좋아, 에뮬레이터에서 ICS를 시도하고 다이얼로그를 살펴볼 것이다. 결과를 게시 할 것입니다! – weilah

답변

1

나는 문제가 여기에있을 수 있습니다 생각 :

View layout = inflater.inflate(R.layout.popup_contact, (ViewGroup) findViewById(R.id.ppc_llContact)); 

당신은 아주이다,에 "반환 된 계층 구조의 루트의 LayoutParams 값의 집합을 제공 목적"으로 당신의 활동의 일부 레이아웃 ppc_llContact를 사용 이 레이아웃은 대화 상자의 최종 계층 구조에 참여하지 않기 때문에 무의미합니다.

사용이 대신은 :

ppEnviarMsg.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
//FILL_PARENT is an example 
+0

헤이, 두 번째 옵션은 트릭을했다! 이제는 ppEnviarMsg.getWindow(). getAttributes(). gravity = Gravity.CENTER;를 사용하더라도 문제는 화면 상단에 나타납니다. 왜 그런지 알아? – weilah

+0

예제에서와 같이'LayoutParams.FILL_PARENT'를 사용했다면, 이것 때문에 발생합니다. 대신에 화면의 크기와 관련된 크기를 설정할 수 있습니다 (예 : 2/3) : 'View decorView = getWindow(). getDecorView(); ppEnviarMsg.getWindow(). setLayout (decorView.getWidth() * 2/3, decorView.getHeight() * 2/3); ' –

+0

고맙습니다. 정말 감사. 나는 비슷한 것을했으나'Display display = getWindowManager(). getDefaultDisplay(); '를 사용하여 잘린 것이 더 나을 것입니다. – weilah

관련 문제