2017-01-19 2 views
0

Ich habe ein Android-Layout, das für die Anzeige eines "über App" -Meldungsdialogs mit einer Schaltfläche "Schließen" verwendet wird. Es hat einen Titel in fett zentriert, die App-Version und den Namen des Entwicklers. Alles sieht gut aus, abgesehen davon, dass sich oberhalb des Titels ein sehr deutlicher Rand/Abstand befindet und ich diesen leeren Platz nicht entfernen kann.Android-Warndialog leeren Bereich oben entfernen

Hier ist das Layout:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView android:orientation="vertical" android:scrollbars="none" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginRight="6.0dp" xmlns:android="http://schemas.android.com/apk/res/android"> 

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center"> 
     <TextView android:textSize="16.0dip" android:textStyle="bold" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:layout_marginRight="6.0dip" android:layout_marginBottom="10.0dip" android:text="@string/app_name" /> 
    </LinearLayout> 

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> 
     <TextView android:textSize="14.0dip" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:layout_marginTop="0.0dip" android:text="@string/version_text" /> 
     <TextView android:textSize="14.0dip" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:layout_marginTop="0.0dip" android:text="@string/app_version" /> 
    </LinearLayout> 

    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> 
     <TextView android:textSize="14.0dip" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:text="@string/about_developer" /> 
    </LinearLayout> 

    <LinearLayout android:gravity="center" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip" xmlns:android="http://schemas.android.com/apk/res/android"> 
     <Button android:id="@id/close_btn" android:layout_width="110.0dip" android:layout_height="44.0dip" android:layout_marginTop="4.0dip" android:layout_marginBottom="4.0dip" android:text="@string/about_close" /> 
    </LinearLayout> 

    </LinearLayout> 
</ScrollView> 

Und hier ist es, was es zeigt:

about dialog window

Ich habe android:layout_marginTop="-10.0dip" Attribut in vielen Tags versucht, das Hinzufügen und SO für ein ähnliches Problem gesucht, aber ich kann‘ t finde es. Ich wäre dankbar, wenn mir jemand zeigt, wie dieses Problem gelöst wird.

Antwort

3

Sie könnten versuchen, machen versuchen, Ihren eigenen Dialog mit einer benutzerdefinierten Ansicht unter Verwendung eines DialogFragment und setzen Sie diese

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 

Oder vielleicht nur ein einfaches Dialog zu bedienen, kein AlertDialog wie diese

Dialog dialog = new Dialog(theContext); 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setContentView(yourCustomView); 
dialog.show(); 
+0

ich mit der gleichen Antwort auf halbem Weg war. Gut gemacht. –

+0

Ich versuche, Ihre Antwort anwenden und Android Studio sagt mir, dass "MainActivity ist keine einschließende Klasse" irgendwelche Ideen? Bitte helfen Sie. –

+0

bearbeitet! stell den Kontext! – DevAndroid

0

Verwenden Sie stattdessen ein RelativeLayout (der folgende Code muss an Ihre Bedürfnisse angepasst werden, aber es gibt das allgemeine Layout):

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<TextView 
    android:text="App Name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:id="@+id/textView" /> 

<TextView 
    android:text="Version 1.0" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="29dp" 
    android:id="@+id/textView2" /> 

<TextView 
    android:text="Developed by Name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView2" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="23dp" 
    android:id="@+id/textView3" /> 

<Button 
    android:text="Close" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView3" 
    android:layout_alignLeft="@+id/textView2" 
    android:layout_alignStart="@+id/textView2" 
    android:layout_marginTop="42dp" 
    android:id="@+id/button2" /> 
</RelativeLayout> 

Sie können auch einen Dialog verwenden, wie von anderen bereits erwähnt.

EDIT:

können Sie versuchen, eine benutzerdefinierte mit Dialog statt dann eine DialogFragment verwenden. Um den Dialog aufzurufen, verwenden Sie diese: new CustomDialogFragment().show(getSupportFragmentManager(), "mydialog");

erstellen Sie eine neue Klasse erweitern DialogFragment, und verwenden Sie so etwas wie dies:

public class DonateDialogFragment extends DialogFragment implements View.OnClickListener 
{ 

private AlertDialog dialog; 

public interface CustomDialogListener { 
    void buttonClicked(); 
} 

@Override 
public void onAttach(Activity activity) { 
    super.onAttach(activity); 
    if (!(activity instanceof CustomDialogListener)) { 
     throw new ClassCastException(activity.toString() + " must implement CustomDialogListener"); 
    } 
} 

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder customDialogMain = new AlertDialog.Builder(getActivity()); 
    donateDialogMain.setCancelable(true); 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    View view = inflater.inflate(R.layout.--YOUR-CUSTOM-DIALOG-LAYOUT-HERE--, null); 

    view.findViewById(R.id.close_btn).setOnClickListener(this); 

    customDialogMain.setView(view); 

    dialog = customDialogMain.show(); 
    return dialog; 
} 

public void onClick(View v) { 
    // does something very interesting 
    switch (v.getId()) 
    { 
     case R.id.close_btn: 
      ((CustomDialogListener) getActivity()).buttonClicked(); 
      dialog.dismiss(); 
      break; 
    } 
} 

}

+0

Ich habe das XML angepasst und es ausprobiert, das Problem besteht immer noch. –

+0

Ich habe Schritte hinzugefügt, um stattdessen einen Dialog zu verwenden. :) –

0

können Sie diesen Stil direkt verwenden, um style.xml

<style name="Theme.UserDialog.AppCompat" parent="Theme.AppCompat.Dialog"> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowCloseOnTouchOutside">true</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
    <item name="android:windowBackground">@android:color/white</item> 
    <item name="android:minWidth">600dp</item> 
</style> 

Wenden Sie diesen Stil auf die Aktivitätsklasse, die Sie als Warndialog

setzen will
android:theme="@style/Theme.UserDialog.AppCompat" 

und startet Aktivität Intent mit wie

Intent activity= new Intent(this, AlertActivity.class); 
startActivity(activity); 
Verwandte Themen