Layoutänderung durch änderung des Parents (vermutlich durch Keyboard)

1

12nico07

Neues Mitglied
0
Nachdem mein schöner uns ausführlicher Text nicht gepostet wurde, da ich plötzlich ausgeloggt war, hier nochmal die Kurzfassung.

Ich habe 1 Activity mit 4 Fragments. Durch Swypen kann man durch die Fragments navigieren. Am "bottom" des Parents ist in jedem Fragment ein Hinweis ("Durch swypen können Sie navigieren...") und ein Bild, das zeigt in welchem Fragment man gerade ist.

Im Fragment 2 ("setup_two") kann man ein Passwort für die App setzten. Um Schreibfehler auszuschließen gibt es zwei EditText Elemente. Diese haben einen TextWatcher. Bei jeder Änderung in einem der EditText wird geprüft ob die beiden Texte übereinstimmen. Wenn nein, wird dies per Text auf dem Fragment ausgegeben.

Wenn ich nun im ersten EditText Element ein Passwort eingebe, bekomme ich die Nachricht das die beiden Passwörter nicht übereinstimmen. Wenn ich dann im zweiten EditText absichtlich einen Fehler im Passwort mache, ebenso.
Wenn ich allerdings im zweiten EditText Element dann das gleiche Passwort eingebe, zerreist es mir mein Layout und das Navigationsbild und der Navigationstext stehen direkt über den EditText Elementen. Es sieht aus als würde sich das Parent plötzlich ändern, jedoch nur wenn die Passwörter übereinstimmen - wenn sie falsch sind passiert das nicht.

Anbei das Problem als Screen:

1) So sieht es ganz am Anfang aus:
show.php


2) Das erste Passwort wurde eingegeben:


3) Das zweite Passwort wurde falsch eingegeben:


4) Das zweite Passowrt wurde korrekt eingegeben:



Und hier noch der Code:

1) Das Layout XML File:
Code:
<?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:padding="16dp"
    android:background="#FFFFFF">

    <!-- Überschrift -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/lbl_setup_b_head"
        android:id="@+id/lbl_head"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textSize="30sp"
        android:layout_marginBottom="4dp"
        android:textColor="#000000"/>

    <!-- Warum ein Passwort -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lbl_setup_b_1"
        android:id="@+id/lbl_whyPW"
        android:layout_below="@+id/lbl_head"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="20dp"
        android:textColor="#000000"/>

    <!-- Hinweis ob die PW übereinstimmen -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="@string/pw_vergleich_default"
        android:id="@+id/lbl_pwVergleich"
        android:layout_below="@+id/lbl_whyPW"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="20dp"
        android:textColor="#000000"/>

    <!-- Passworteingabe Label -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lbl_setup_b_pw"
        android:id="@+id/lbl_pw"
        android:textColor="#000000"
        android:layout_below="@+id/lbl_pwVergleich"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="10dp"
       />

    <!-- Passworteingabe EditText    -->
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/txt_pw"
        android:textColor="#000000"
        android:shadowColor="#000000"
        android:layout_below="@+id/lbl_pwVergleich"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/lbl_pw"
        android:layout_toEndOf="@+id/lbl_pw"
        />

    <!-- Passworteingabe Wiederholung Label -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lbl_setup_b_pw2"
        android:id="@+id/lbl_pw2"
        android:textColor="#000000"
        android:layout_below="@+id/lbl_pw"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="20dp"
        android:layout_marginRight="10dp"
        />

    <!-- Passworteingabe Wiederholung EditText   -->
    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/txt_pw2"
        android:textColor="#000000"
        android:shadowColor="#000000"
        android:layout_below="@+id/lbl_pw"
        android:layout_alignParentRight="true"
        android:layout_alignLeft="@+id/txt_pw"
        android:layout_alignStart="@+id/txt_pw"
        />

    <!-- Wie kann ein Passwort aussehen Label -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lbl_setup_b_2"
        android:id="@+id/lbl_pwAnforderung"
        android:textColor="#000000"
        android:layout_below="@+id/lbl_pw2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="20dp" />


    <!-- Unterstes Textelement (Hinweis zum wischen)-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/lbl_swipe2goOn"
        android:id="@+id/lbl_swipe2goOn"
        android:layout_above="@+id/imgView_Navi"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:textColor="#000000" />


    <!-- Navigationsbild -->
    <ImageView
        android:layout_width="80dp"
        android:layout_height="20dp"
        android:id="@+id/imgView_Navi"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/navi_2" />

</RelativeLayout>


2) Die .java Datei des Fragments:
Code:
public class setup_two extends Fragment {

    Passwort  myInterface;
    EditText myText_A;
    EditText myText_B;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        final View myview = inflater.inflate(R.layout.setup_two_layout, container, false);

        myText_A = (EditText) myview.findViewById(R.id.txt_pw);
        myText_B = (EditText) myview.findViewById(R.id.txt_pw2);


        TextWatcher myWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {


            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                String pw_1 = myText_A.getText().toString();
                String pw_2 = myText_B.getText().toString();
                myInterface.sendPasswort(pw_1, pw_2);

                TextView mytext = (TextView) myview.findViewById(R.id.lbl_pwVergleich);
                if (myText_A.getText().toString().length() > 0 || myText_B.getText().toString().length() > 0) {
                    //Toast.makeText(getActivity(), "Hallo", Toast.LENGTH_SHORT).show();

                    if (myText_A.getText().toString().equals(myText_B.getText().toString())) {
                        mytext.setTextColor(Color.BLACK);
                        mytext.setVisibility(View.INVISIBLE);
                        myText_A.setTextColor(Color.BLACK);
                        myText_B.setTextColor(Color.BLACK);
                    } else {
                        mytext.setVisibility(View.VISIBLE);
                        mytext.setTextColor(Color.RED);
                        mytext.setText(R.string.pw_vergleich_ungleich);
                        myText_A.setTextColor(Color.RED);
                        myText_B.setTextColor(Color.RED);

                    }
                } else {
                    mytext.setVisibility(View.VISIBLE);
                    mytext.setTextColor(Color.BLACK);
                    mytext.setText(R.string.pw_vergleich_default);

                }

            }
        };

        myText_A.addTextChangedListener(myWatcher);
        myText_B.addTextChangedListener(myWatcher);

        return myview;
    }

    interface Passwort {
        public void sendPasswort(String pw_1, String pw_2);
    }


    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            myInterface = (Passwort) activity;
        }
        catch (ClassCastException e) {
            throw new ClassCastException("You need to implement sendData method");
        }
    }
}
 
Der "Fehler" liegt im Layout. Du benutzt ein RelativeLayout. Die beiden letzten Views befinden sich immer am bottom des RelativeLayout. Wenn die Tastatur schon offen ist, wird die Höhe des RelativLayout kleiner, d.h. der untere Rand befindet sich oberhalb der Tastatur. Was zur der Überlagerung in deinem letzten Screen führt.
 
OK, es war auch meine Vermutung, dass durch die Tastatur das Layout verkleinert wird und die Elemente deswegen hoch rutschen.
Ich möchte halt, dass die Elemente bei jedem Smartphone immer am unteren Bildschirm Rand sind und bei großen Smartphones nicht irgendwo in der Mitte. Darum die "bottom" plazieren.
Hast du einen Tipp wie ich das machen kann?
 

Ähnliche Themen

A
Antworten
1
Aufrufe
641
swa00
swa00
C
Antworten
1
Aufrufe
860
jogimuc
J
J
  • JoEntwickler
Antworten
8
Aufrufe
1.357
JoEntwickler
J
Zurück
Oben Unten