0

我正在開發一款適用於平板電腦的Android應用程序。我實現了一個DialogFragment看起來像這樣:使用對話框的Android佈局問題

enter image description here

的XML佈局由該代碼中定義:

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentTop="true"> 
     <EditText 
      android:id="@+id/destinatario_messaggio" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:inputType="text" 
      android:hint="Destinatario del messaggio" 
      android:textColor="#000000" 
      android:textSize="24dp"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentBottom="true" 
     android:background="#FFFFFF"> 
     <View android:layout_width="fill_parent" 
      android:layout_height="1dip" 
      android:background="#888888" /> 
     <EditText 
      android:id="@+id/body_messaggio" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="20dp" 
      android:inputType="textMultiLine" 
      android:text="" 
      android:hint="Scrivi Messaggio" 
      android:textColor="#000000" 
      android:textSize="24dp" 
      android:maxLines="5"/>  
    </LinearLayout> 
</RelativeLayout> 

我有兩個問題:

1 - 由於我使用平板電腦,我希望我的對話框左側和右側的所有可用空間都從對話框本身填充。即使我的根查看已經設置好的此:

的android:layout_width =「match_parent」

我的對話框是浮動在活動的中心,讓可用的一個很大的空間在左側,在它的右邊。 我的對話框如何佔用設備中的所有可用寬度?

2-當鍵盤(IME)出現用於編輯EditText字段時,我的對話框被隱藏在對話框的頂部(標題和第一個TextView變爲不可見)。相反,我想要的是,對話框頂部保持在頂部,而Dialogis的中心「壓縮」。這似乎是我的佈局不適應新的可用空間。

+0

機器人:windowSoftInputMode = 「adjustPan」 嘗試此,或adjustSize對於第二個問題或getWindow()setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);而不是always_hidden屬性,將其改爲adjustpane –

+0

我可以指定android:windowSoftInputMode =「adjustPan」? – GVillani82

+0

我提到你用它在任何地方先生,我只是說試試看。雖然通常它是一個清單標籤,所以當軟鍵盤打開時使用代碼來調整窗口 –

回答

0

對於你的第一部分,使對話框填充寬度使用。

dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT; 
+1

謝謝@Brontok,但它不起作用! – GVillani82