Benutzerdefinierte Dialogfeld zu klein
Ich habe ein android-Aktivität, die eine benutzerdefinierte Dialogfeld.Die Anwendung läuft ok, aber der dialog ist zu klein,ich will ein größeres display-dialog.Wie kann ich das erreichen?
Hier ist mein layout-xml -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/view_more_borders">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="4dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/share_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Company Name:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue"
android:typeface="sans" />
<TextView
android:id="@+id/textViewCompanyName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.80"
android:text=" "
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Price per share:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />
<TextView
android:id="@+id/textViewprice_pershare"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_alignBaseline="@+id/Yesterday"
android:layout_alignBottom="@+id/Yesterday"
android:layout_marginLeft="38dp"
android:fontFamily="sans-serif"
android:layout_toRightOf="@+id/company"
android:text=" "
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Total cost:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />
<TextView
android:id="@+id/textview_totalcost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_alignBaseline="@+id/Yesterday"
android:layout_alignBottom="@+id/Yesterday"
android:layout_marginLeft="38dp"
android:fontFamily="sans-serif"
android:layout_toRightOf="@+id/company"
android:text=" "
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Number of shares:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />
<EditText
android:id="@+id/shareNumber"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:inputType="number"
android:fontFamily="sans-serif"
android:textSize="12sp"
>
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="4dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Payment method:"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/nice_blue" />
<Spinner
android:id="@+id/spinner_paymentmode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" />
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/button_buy_shares"
style="@style/ButtonText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/blue_button"
android:text="Buy" />
Und hier ist meine Ausgabe.Ich will erhöhen Sie die Breite und Höhe des dialogs.
Und meine java-Datei
public class MyDialogFragment extends DialogFragment {
public MyDialogFragment() {
}
private EditText mEditText;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialogfragment, container);
//mEditText = (EditText) view.findViewById(R.id.txt_your_name);
//getDialog().setTitle("Hello");
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
return view;
}
}
- Posten Sie Ihre java-Datei. setzen Sie Breite und Höhe des dialogs in der java-Datei.
- ich habe es gepostet.
- haben Sie Ihr problem gelöst?
- Nein,bin immer noch versuchen herauszufinden, etwas von google
- versuchen Sie es erneut mein Stück code.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ändern Sie Ihre dialog-dimension-Laufzeit:
Können Sie tun, dass für beide dimension, in meinem Beispiel habe ich nur verändert die Breite.
Hoffe, es hilft!
BEARBEITEN
Ich vergaß zu erwähnen, wo ich mich Breite:
EDIT 2
Versuchen, diesen code:
getActivity().getWindow()
stattgetDialog().getWindow()
und Hinweis: diese muss einberufen werden, inonStart()
wenn das ui fertig ist und nicht inonCreate()
.Einstellung android:minWidth und android:minHeight in das benutzerdefinierte layout wird den trick für mich.
setzen Sie folgende Zeile in die onCreate
original Antwort
Theme_DeviceDefault_Dialog_MinWidth
,Theme_DeviceDefault_Light_Dialog_NoActionBar_MinWidth
oder material. Auch die Einstellungstyle
oderandroid:theme
im layout nicht lösen, so sollten wir diese Methode verwendensetStyle()
.Verwenden Sie diese in
style.xml
- Datei und verwenden Sie diesen Stil im Dialogfeld KlasseDie richtige Lösung ist, überschreiben die
onCreateDialog
Methode eher alsonCreateView
, und erstellen Sie Ihren dialog mit einemAlertDialog.Builder
verwenden, wie beschrieben in der doc: http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialogAlertDialog.Builder
, es wird nicht helfen.Dialoge sind so bemessen, durch deren Inhalt. Sie können hinzufügen, Polsterung und Margen auf den äußeren layout, um mehr Speicherplatz, aber Sie werden nicht weitergeben, ist die Aussicht von innen.
Versuchen, diese
Für Dialogfeld Breite und Höhe pro Gerät Bildschirmgröße
versuchen
android:layout_height
um einen Wert für die Basis -LinearLayout
beispielsweise
Hinzufügen android:minWidth /android:minHeight Sie Ihr root-Ansicht. Siehe Beispiel unten: