- Forum-Beiträge: 2
18.02.2018, 13:09:52 via Website
18.02.2018 13:09:52 via Website
Hey Leute, ich bin neu hier und seit 3 Tagen befasse ich mich nun ausschließlich mit der Aufabe ein Layout in Android Studio zu entwerfen.
Hat auch alles soweit geklappt, sieht aus wie ich es haben wollte und das nach hundert versuchen in hundert verschiedenen Möglichkeiten der Ausführung. Dennnoch habe immer und immer wieder den selben Fehler der mich mittlerweile zur Verzweiflung bringt.
Ich habe ein Header Element für z.b. den App Namen, dann ein Footer Element für eine Texteingabe per EditText und dazwischen plaziert ist eine ScrollView.
In der ScrollView ein LinearLayout welches in Vertikaler anordnung so viele Elemente enthält dass ein Scrollen notwenig wird.
[Bild1]
(eigentlich sollte hier schon im Layout der letzte Text unten zu sehen sein statt der erste am oberen anfang, aber dazu später mehr)
Wenn ich jetzt runterscrolle zum Ende und dann auf EditText drücke wird die Tastatur aufgerufen und überdeckt das was am unteren Ende der ScrollView zu sehen ist und das ist nicht gewünscht.
[Bild2]
(runter gescrollt)
[Bild3]
(Tastatur eingeblendet, so sieht es zur Zeit aus)
Ich möchte aber dass der untere Bereich der zu sehen ist vom Inhalt der ScrollView auch zu sehen ist wenn die Tastatur eingeblendet wurde.
[Bild4]
(so sollte das Ergebnis aussehen wenn die Tastatur eingeblendet wurde)
Wenn ich das LinearLayout innerhalb der ScrollView auf layout_gravity="bottom" scheint genau das zuerst zu klappen was mir auch logisch erschien, aber dann passiert leider dass der obere bereich der nicht zu sehen ist abgeschnitten wird und beim scrollen nach unten ein leerraum entsteht der dem oben abgeschnittenen bereich in der höhe identisch ist.
[Bild5]
(Hier scrollt man in die falsche Richtung sozusagen deshalb hab ich es wieder auf top gesetzt)
Per Code mit ScrollView.FOCUS_DOWN funktioniert zwar als Notlösung aber ich denke es wäre sinnvoller das direkt übers Layout zu machen um nicht per code auf jede Layoutveränderung zu reagieren.
Im OnCreate rufe übrigens ich folgende Parameter auf um eine allgemeine Layoutverschiebung zu verhindern.
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Ich weiss nach stundenlangem googeln und experimentieren nun keinen Rat mehr und hoffe dass mir einer nach meiner Lebensgeschichte hier vielleicht helfen kann zumindest der Lösung ein wenig näher zu kommen.
Ich möchte einfach nur das ScrollView statt oben den Focus immer auf unten bzw auf die aktuelle Position hat und sich bei einer Layoutveränderung eben nur nach oben verschiebt aber nicht nach unten oder stehen bleibt. Alles andere Funktioniert jedenfalls nach meinen Vorstellungen.
Danke schonmal für eure Hilfe
Hier noch der Code der LayoutDatei:
<android.support.constraint.ConstraintLayout
xmlns:android="schemas.android.com/apk/res/android"
xmlns:app="schemas.android.com/apk/res-auto"
android:id="@+id/activity_test"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#212121"
android:text=" List"
android:textSize="35sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/footer"
android:background="#212121"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
>
<EditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Add Text..."
android:textSize="14sp"
/>
</LinearLayout>
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
android:isScrollContainer="false"
app:layout_constraintBottom_toTopOf="@+id/footer"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header"
android:scrollIndicators="bottom"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"> //if i set to Bottom scrollbar scrolls wrong way see: [Bild5]
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
>
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text1" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text2" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text3" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text4" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text5" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text6" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text7" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text8" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text9" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text10" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text11" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text12" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text13" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text14" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text15" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text16" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text17" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text18" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text19" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text20" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text21" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text22" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text23" />
<TextView
android:layout_width="match_parent"
android:layout_height="20dp"
android:text="Text24" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
— geändert am 18.02.2018, 13:22:05
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.