2013-01-14 8 views
0

오늘 문제는 Android 2.3.5에서 사용자 정의 대화 상자가 잘못 표시된다는 것입니다. 대화 상자 너비가 넓어야합니다. AlertDialog가 예상보다 넓습니다

enter image description here

나는 어떤 성공 LinearLayout 같이 TextView20dp 대신 wrap_content를 사용했습니다. 나는 wrap_content으로 Android 4에있는 사각형 모양을 얻고 싶습니다.

다음은이 사용자 정의 대화 상자의보기 용 XML 코드입니다. 여기

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="Please wait" > 
    </TextView> 
</LinearLayout> 

는이, 다른 어떤 중요한 사용자 정의 대화의 코드가 아닙니다이다. 그것을 좋아 보이는 있도록 안드로이드 4.0.3에

AlertDialog.Builder builder = new AlertDialog.Builder(context); 
     AlertDialog dialog; 

     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.dialog_progressdialog, 
             null); 

     builder.setView(layout); 

     //initializing textview 

     dialog = builder.create(); 

     //do other stuff 

나는, 사각형을 얻을 - 내가 원하는대로로한다. 문제는 무엇이겠습니까? 누구도 이런 종류의 문제를 발견합니까? 죄송합니다. Android 4에 대한 샘플이 없습니다. 오늘 전화를 보내실 샘플이 없습니다. 내가 안으로 넣으면


progressbar 나는 안드로이드 4 정사각형을 만들 수 있어요,하지만 안드로이드 2.3에서 작업을 수행하는 것은 불가능합니다.

안드로이드 2.3.5

enter image description here

안드로이드 4.0.4

enter image description here

답변

0

하려고 시도합니다. ProgressDialog를 화면의 중앙에두고 싶습니다. 나는 안드로이드 2.2. *에 그것을 구현하고 안드로이드 4에서도 모든 장치에서 완벽하게 작동합니다. *

나는 또한 사용자 정의 progressDialog에 스타일을 사용하고 있습니다. 아래에서 내 코드를 보시면 알 수 있습니다.

자바 코드 :

final Dialog dialog = new Dialog(SplashActivity.this,R.style.CustomDialogTheme); 
     dialog.getWindow(); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     dialog.setContentView(R.layout.internet_dialog); 
     dialog.setCancelable(false); 

     Button retryBtn = (Button) dialog.findViewById(R.id.retryBtn); 
     Button cancel = (Button) dialog.findViewById(R.id.cancelBtn); 

     retryBtn.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View arg0) { 
       dialog.dismiss(); 
            // Some task 
      } 
     }); 

     cancel.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View arg0) { 
       dialog.dismiss(); 
            // Some task 
      } 
     }); 
     dialog.show(); 
    } 

CustomDialogTheme

<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog"> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
    <item name="android:fitsSystemWindows">true</item> 

    <!-- <item name="android:colorBackgroundCacheHint">#00000000</item> 
    <item name="android:background">#00000000</item> --> 

</style> 

그리고 내 레이아웃 XML 파일은 다음과 같습니다 internet_dialog.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#00000000" 
    android:orientation="vertical" > 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/popup_shape" 
     android:layout_margin="10dp" 
     android:orientation="vertical" 
     > 

     <TextView 
      android:id="@+id/net_popup_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="@string/internet_popup_heading" 
      android:layout_marginTop="15dp" 
      android:textColor="#ffffff" 
      android:textSize="20dp" /> 

     <TextView 
      android:id="@+id/net_msg" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_margin="20dp" 
      android:gravity="center" 
      android:text="@string/internet_popup_msg" 
      android:textColor="#ffffff" 
      android:textSize="14dp" /> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:orientation="horizontal" 
      android:gravity="center" 
      android:layout_gravity="center_horizontal" 
      android:padding="5dp" > 

      <Button 
       android:id="@+id/retryBtn" 
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="2dp" 
       android:background="@drawable/blue_button" 
       android:textColor="#000000" 
       android:textStyle="bold" 
       android:text="@string/internet_popup_retry" /> 

      <Button 
       android:id="@+id/cancelBtn" 
       android:layout_width="0dp" 
       android:layout_weight="1" 
       android:layout_marginLeft="2dp" 
       android:layout_height="wrap_content" 
       android:background="@drawable/blue_button" 
       android:textColor="#000000" 
       android:textStyle="bold" 
       android:text="@string/internet_popup_exit" /> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 

여기에, 난 개미를 줄를 havent 고치다 높이/너비는 모든 장치의 모든 레이아웃에서 완벽하게 보입니다.

대화 상자에 스타일을 추가하고 결과를 확인하십시오. 희망이 있으면 도움이 될 것입니다.

의견을 주시기 바랍니다. 코딩 즐기기 ... :)

0

그냥 코드, 당신은 레이아웃 PARAMS를에 추가 할 수있는 모든 플랫폼에서 동일하게 동작하는지 확인하는 방법 다음과 같은 대화 상자보기 :

layout.setLayoutparams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

dialog.setView(layout);

확인의 작업 주위에,하지만 당신은 아이디어를 벗어 만약 내가이 문제에 대한 생각으로, 당신은 시도 할 수 있습니다 : Paint.measureText();를 사용하여 텍스트보기의

calulate 길이를하고 설정 대화보기 매개 변수에. layout.setLayoutparams(new LinearLayout.LayoutParams(LENGTH_CALCULATED, LayoutParams.WRAP_CONTENT));

+0

작동하지 않는 것 같습니다. – deadfish

+0

작동하지 않는다는 것은 어떤 오류 또는 동일한 결과를 의미합니까? – akkilis

+0

나는 동일한 결과를 얻는다 – deadfish

0

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(layout); 
builder.setTitle("Title"); 
alertDialog = builder.create(); 
alertDialog.show(); 
alertDialog.getWindow().setLayout(600, 400); //Controlling width and height. 

이 또한 내가 무슨 코드를 잘못 몰라이

alertDialog.show(); 
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 

lp.copyFrom(alertDialog.getWindow().getAttributes()); 
lp.width = 150; 
lp.height = 500; 
lp.x=-170; 
lp.y=100; 
alertDialog.getWindow().setAttributes(lp); 
+0

setLayout가 작동하지만 100x100으로 설정하면 직사각형이된다. – deadfish

+0

무엇을 원 하나? 다른 하나의 해결책을 시도하십시오. –

+0

예, 두 개의 텍스트 뷰 요소를 세로 방향으로 배치하면 두 번째 요소가 잘립니다. 대화 상자 차원에이 요소가 표시되지 않습니다. 대화 상자 높이가 매우 작습니다. 텍스트 뷰는 중력 중심이 아닙니다. 다른 매개 변수를 무시한 것처럼 – deadfish