2016-03-25 9 views
-1

In meinem benutzerdefinierten Dialogfeld versuche ich, meine Checkbox unter meinem scrollview zu bleiben, aber es funktioniert nicht. Ich habe versucht, das Kontrollkästchen unter der Scrollview in Xml, aber es erscheint nicht, wenn ich die App ausführen. Was muss getan werden, damit das Kontrollkästchen am unteren Rand des Dialogfelds (unterhalb der Bildlaufansicht) bleibt und nicht Teil der Bildlaufansicht ist, wenn ich es blättern lasse? Ich möchte nicht, dass meine Checkbox mit dem Scrollview blättert.CheckBox bleibt nicht am unteren Ende des Dialogs

java

LayoutInflater inflater = LayoutInflater.from(this); 
View dialog_layout = inflater.inflate(R.layout.fragment_overlay, (ViewGroup) findViewById(R.id.Overlay_linearLayout)); 
AlertDialog.Builder db = new AlertDialog.Builder(this); 
db.setView(dialog_layout); 
db.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
}); 
db.show(); 

xml

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Overlay_linearLayout" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/Overlay_scrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/Overlay_tableLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0"> 
     <TableRow 
      android:padding="10dp"> 
      <ImageView 
       android:layout_width="0px" 
       android:layout_weight="0.3" 
       android:layout_height="80dp" 
       android:src="@drawable/img_0" /> 
      <TextView 
       android:id="@+id/MapOverlay_textView0" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction0" /> 
     </TableRow> 
     <TableRow 
      android:padding="10dp"> 
      <ImageView 
       android:layout_width="0px" 
       android:layout_weight="0.3" 
       android:layout_height="80dp" 
       android:src="@drawable/img_1" /> 
      <TextView 
       android:id="@+id/MapOverlay_textView1" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction1" /> 
     </TableRow> 
     <TableRow 
      android:padding="10dp"> 
      <ImageView 
       android:layout_width="0px" 
       android:layout_weight="0.3" 
       android:layout_height="80dp" 
       android:src="@drawable/img_2" /> 
      <TextView 
       android:id="@+id/MapOverlay_textView2" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction2" /> 
     </TableRow> 
     <TableRow 
      android:padding="10dp"> 
      <ImageView 
       android:layout_width="0px" 
       android:layout_weight="0.3" 
       android:layout_height="80dp" 
       android:src="@drawable/img_3" /> 
      <TextView 
       android:id="@+id/MapOverlay_textView3" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction3" 
       style="@android:style/TextAppearance.Medium" /> 
     </TableRow> 
     <TableRow> 
      <CheckBox 
       android:text="Don't show this again" 
       android:id="@+id/skip" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </TableRow> 
    </TableLayout> 
</ScrollView> 

+0

ziehen 'CheckBox' aus dem' ScrollView', und sie beide in einer anderen 'ViewGroup' setzen; z. B. ein vertikal ausgerichteter LinearLayout. –

+0

halten Sie 'checkbox' außerhalb' 'ScrollView' 'und wickeln Sie' ScrollView' und 'CheckBox' in' LinearLayout' ein. –

+0

okey Sie können auch 'RelativeLayout' verwenden und' android: alignParentBottom = "true" 'zum Kontrollkästchen hinzufügen. BEARBEITEN: Sie können den zweiten Parameter durch null ersetzen 'View dialog_layout = inflater.inflate (R.layout.fragment_overlay, null);' –

Antwort

1

Try checkbox und ScrolView innerhalb neuer LinearLayout und checkbox wie dies außerhalb des ScrollView setzen zu setzen :

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ScrollView android:id="@+id/Overlay_scrollView" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1"> 

     <TableLayout android:id="@+id/Overlay_tableLayout" 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="1.0"> 

       <ImageView 
        android:layout_width="0px" 
        android:layout_height="80dp" 
        android:layout_weight="0.3" 
        android:src="@drawable/ic_launcher"/> 

       <TextView 
        android:id="@+id/MapOverlay_textView0" 
        android:layout_width="0px" 
        android:layout_weight="0.7" 
        android:text="tion0"/> 


       <ImageView 
        android:layout_width="0px" 
        android:layout_height="80dp" 
        android:layout_weight="0.3" 
        android:src="@drawable/ic_launcher"/> 

       <TextView 
        android:id="@+id/MapOverlay_textView1" 
        android:layout_width="0px" 
        android:layout_weight="0.7" 
        android:text="dada"/> 


       <ImageView 
        android:layout_width="0px" 
        android:layout_height="80dp" 
        android:layout_weight="0.3" 
        android:src="@drawable/ic_launcher"/> 

       <TextView 
        android:id="@+id/MapOverlay_textView2" 
        android:layout_width="0px" 
        android:layout_weight="0.7" 
        android:text="ruction2"/> 


       <ImageView 
        android:layout_width="0px" 
        android:layout_height="80dp" 
        android:layout_weight="0.3" 
        android:src="@drawable/ic_launcher"/> 

       <TextView 
        android:id="@+id/MapOverlay_textView3" 
        style="@android:style/TextAppearance.Medium" 
        android:layout_width="0px" 
        android:layout_weight="0.7" 
        android:text="_instruction3"/> 


     </TableLayout> 
    </ScrollView> 

    <CheckBox 
     android:id="@+id/skip" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Don't show this again"/> 
</LinearLayout> 

UPDATE

Wie xml Datei aufzublasen und zu dialog

LayoutInflater inflater = getLayoutInflater(); 
View dialoglayout = inflater.inflate(R.layout.dialog_layout, null); 
AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setView(dialoglayout); 
builder.show(); 
+0

Was ist mit dieser Codezeile? 'View dialog_layout = inflater.inflation (R.layout.fragment_overlay, (ViewGroup) findViewById (R.id.Overlay_linearLayout));' – MacaronLover

+0

Checkbox erscheint nicht – MacaronLover

+0

hmm in meiner sim es erscheint mit diesem code http: // s27. postimg.org/539925183/Screenshot_8.png, und zum Aufblasen, warum haben Sie nicht das ganze XML-Layout aufgeblasen –

0

Versuchen Sie dies für Ihre Layout-Datei festgelegt. Es ist Ihre XML-Datei mit einigen Änderungen.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/Overlay_linearLayout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<ScrollView 
    android:id="@+id/Overlay_scrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/skip"> 

    <TableLayout 
     android:id="@+id/Overlay_tableLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0"> 

     <TableRow android:padding="10dp"> 

      <ImageView 
       android:layout_width="0px" 
       android:layout_height="80dp" 
       android:layout_weight="0.3" 
       android:src="@drawable/img_0" /> 

      <TextView 
       android:id="@+id/MapOverlay_textView0" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction0" /> 
     </TableRow> 

     <TableRow android:padding="10dp"> 

      <ImageView 
       android:layout_width="0px" 
       android:layout_height="80dp" 
       android:layout_weight="0.3" 
       android:src="@drawable/img_1" /> 

      <TextView 
       android:id="@+id/MapOverlay_textView1" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction1" /> 
     </TableRow> 

     <TableRow android:padding="10dp"> 

      <ImageView 
       android:layout_width="0px" 
       android:layout_height="80dp" 
       android:layout_weight="0.3" 
       android:src="@drawable/img_2" /> 

      <TextView 
       android:id="@+id/MapOverlay_textView2" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction2" /> 
     </TableRow> 

     <TableRow android:padding="10dp"> 

      <ImageView 
       android:layout_width="0px" 
       android:layout_height="80dp" 
       android:layout_weight="0.3" 
       android:src="@drawable/img_3" /> 

      <TextView 
       android:id="@+id/MapOverlay_textView3" 
       style="@android:style/TextAppearance.Medium" 
       android:layout_width="0px" 
       android:layout_weight="0.7" 
       android:text="@string/overlay_instruction3" /> 
     </TableRow> 

    </TableLayout> 
</ScrollView> 

<CheckBox 
    android:id="@+id/skip" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:text="Don't show this again" />