2016-01-23 146 views
0

我爲某些數據輸入創建了一個對話框,並且在某些設備上它沒有填充屏幕,它似乎在包裝內容,但在其他設備上它填滿了屏幕(如我所願)。對話框沒有填充屏幕

Layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin"> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/editSiteLocation_Layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/editSiteLocation" 
      android:inputType="textCapWords" 
      android:hint="Site Location"/> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/editWeatherConditions_Layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <AutoCompleteTextView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/editWeatherConditions" 
      android:inputType="textCapWords" 
      android:completionThreshold="1" 
      android:hint="Weather Conditions"/> 
    </android.support.design.widget.TextInputLayout> 

<Button 
    android:id="@+id/buttonAddSite" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Add" 
    android:layout_gravity="end" 
    style="?attr/buttonBarNegativeButtonStyle"/> 

</LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 

我已在兩個設備進行測試;

的HTC One M9(顯示我多麼希望)

This is what I want

的HTC One M9(顯示我多麼希望)

This is not what I want

回答

0

據我的記憶,你必須操縱編程方式如下:

AlertDialog.Builder yourBuilder = new AlertDialog.Builder(this); 
    Dialog yourDialog = new Dialog(this); 
    //do some stuff with your dialog and builder 
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
    lp.copyFrom(yourDialog.getWindow().getAttributes()); 
    lp.width = WindowManager.LayoutParams.MATCH_PARENT; 
    lp.height = WindowManager.LayoutParams.MATCH_PARENT; 
    yourDialog = yourBuilder.create(); 
    yourDialog.show(); 
    yourDialog.getWindow().setAttributes(lp); 
+0

好的謝謝我會放棄這一點。任何想法,爲什麼它在這種類似的設備呈現不同? –

+0

我認爲這就是供應商如何製造自己的android版本。三星與touchWiz,華爲與EMUI等...... – Opiatefuchs

+0

所以有一個修補程序,發現如果我做了根元素的'RelativeLayout'它似乎也有所需的效果 - 實際上比你提到的方法稍好。我發現使用你描述的對話框的方法比我想要的要寬(從屏幕邊緣到對話邊緣的差距大約是第一張圖片的一半)。 –