Dialoge werden auf Smartphone nur gestaucht angezeigt.

T

txbarth

Ambitioniertes Mitglied
0
Hallo,
ich lasse bei Störungen oder durch Klick auf eine Schaltfläche in der App Dialoge anzeigen und das funktioniert im Emulator alles soweit. Heute habe ich meine App zum ersten Mal im neuen Smartphone mit Android Marshmellow testen wollen und musste feststellen, dass die Dialoge alle gestaucht angezeigt werden. Der Rahmen der Dialoge ist viel zu klein als wenn das Layout Content-wrap nicht richtig versteht, der Inhaltsbereich wird dadurch abgeschnitten. Der Titelbereich des Dialogs ist sogar gar nicht zu sehen. Hier das Layout eines einfachen Dialoges.

HTML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="#1c1b1a"
              android:gravity="center_vertical|center_horizontal">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|center_horizontal"
        android:layout_marginTop="10dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_sender_on"
            android:id="@+id/senderimage"
            android:contentDescription="SenderImage"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/dialog_net_ok"
            android:textColor="#FFFFFF"
            android:id="@+id/netstatus"
            android:layout_marginLeft="10dp"/>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_uparrow"
            android:id="@+id/upimage"
            android:contentDescription="UpImage"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="0.00"
            android:textColor="#FFFFFF"
            android:id="@+id/uptext"
            />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_downarrow"
            android:id="@+id/downimage"
            android:contentDescription="DownImage"
            android:layout_marginLeft="20dp"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="0.00"
            android:textColor="#FFFFFF"
            android:id="@+id/downtext"/>
    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_close"
        android:id="@+id/dialogButtonControl"
        />

</LinearLayout>

Ich verwende die Basisklasse Dialog, da die Inhalte der Dialoge sich meist bei der Anzeige ändern (können).

Code:
    dialogNetStatus = new Dialog(MainActivity.this);
    dialogNetStatus.setContentView(R.layout.dialog_netstatus);
    dialogNetStatus.setTitle(R.string.dialog_title_apptraffic);
    dialogNetStatus.setOnDismissListener(new DialogInterface.OnDismissListener() {
      @Override
      public void onDismiss(DialogInterface dialog) {
        Report.print("MainActivity dialogNetStatus.onDismiss");

        checking_netstatus = false;
      }
    });
usw.

Jemand eine Idee, warum das Layout auf dem Smartphone Probleme macht?
 
Hallo,
an dem Layout ist wohl alles in Ordnung. Man muss bei Dialogen ab Lollipop das Motiv dem Konstruktor mit übergeben. So steht dann im Code:

Code:
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(context);
    }

oder wie bei mir

Code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  dialogNetStatus = new Dialog(this, android.R.style.Theme_Material_Dialog_Alert);
} else {
  dialogNetStatus = new Dialog(this);
}
dialogNetStatus.setContentView(R.layout.dialog_netstatus);
 

Ähnliche Themen

M
  • MikelKatzengreis
Antworten
5
Aufrufe
130
swa00
swa00
B
Antworten
4
Aufrufe
493
bb321
B
Zurück
Oben Unten