0

Hey StackOverflow-Community.EditText und Textview nicht im Layout angezeigt

Ich arbeite gerade an einer Android-App und ich habe ein Problem mit dem Layout eines Fragments.

Mein Problem ist, dass die Textansichten und Edittexte nicht angezeigt werden, sie sind wie Squeeze in den Layout-Design-Modus von Android Studio. Das gleiche gilt, wenn ich die App im Emulator starte. Ich verwende eine relativeLayout und die Schwerkraft ist auf den unteren Rand gesetzt.

Ich habe versucht, andere Sache wie die Schwerkraft, die Layouthöhe für die relativeLayout und die TextView/editText ändern, aber nichts funktioniert. Hier ist die XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.project.vincent.activityplanner.InfoPanelActivity" 
android:gravity="bottom"> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_above="@+id/textView3" 
    android:text="test" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_alignParentStart="true" 
    android:layout_above="@+id/dateStart" 
    android:text="test" /> 

<TextView 
    android:id="@+id/textView4" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_alignParentStart="true" 
    android:layout_above="@+id/dateStart" 
    android:layout_alignBottom="@+id/dateStart" 
    android:text="Start" /> 

<EditText 
    android:id="@+id/dateStart" 
    android:layout_width="80dp" 
    android:layout_height="wrap_content" 
    android:inputType="date" 
    android:ems="10" 
    android:layout_toStartOf="@+id/timeStart" 
    android:layout_alignBottom="@+id/timeStart" /> 

<EditText 
    android:id="@+id/timeStart" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:inputType="time" 
    android:ems="10" 
    android:layout_above="@+id/timeEnd" 
    android:layout_alignParentEnd="true" /> 

<TextView 
    android:id="@+id/textView5" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_alignParentStart="true" 
    android:layout_above="@+id/dateEnd" 
    android:text="Start" /> 

<EditText 
    android:id="@+id/dateEnd" 
    android:layout_width="80dp" 
    android:layout_height="wrap_content" 
    android:inputType="date" 
    android:ems="10" 
    android:layout_toStartOf="@+id/timeEnd" 
    android:layout_alignBottom="@id/timeEnd"/> 

<EditText 
    android:id="@+id/timeEnd" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:inputType="time" 
    android:ems="10" 
    android:layout_above="@+id/ratingBar" 
    android:layout_alignParentEnd="true" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Save" /> 

<RatingBar 
    android:id="@+id/ratingBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" /> 

</RelativeLayout> 

Nur die Taste speichern und die Bewertungsleiste werden korrekt angezeigt.

Layout-Ergebnis

Layout result

Layout-Erwartung

Layout expectation

Wenn Sie eine Idee haben, wie dieses Problem lösen würde ich schätzen wirklich Ihre Hilfe.

Dank

+0

, was Sie führen wollen, Screenshot – USKMobility

+0

Aktien Ihre Mockup anhängen hier – Darshak

+0

Ich habe meinen Beitrag gerade bearbeitet das Ergebnis erwartet hinzuzufügen.Danke – Gnarkkkkk

Antwort

1
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.project.vincent.activityplanner.InfoPanelActivity" 
    android:gravity="bottom"> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="visible" 
     android:layout_above="@+id/textView3" 
     android:text="test2" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="visible" 
     android:layout_alignParentStart="true" 
     android:layout_above="@+id/dateStart" 
     android:text="test3" /> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:visibility="visible" 
     android:layout_alignParentStart="true" 
     android:layout_above="@+id/dateStart" 
     android:layout_alignBottom="@+id/dateStart" 
     android:text="Start" /> 

    <EditText 
     android:id="@+id/dateStart" 
     android:layout_width="80dp" 
     android:layout_height="wrap_content" 
     android:inputType="date" 
     android:ems="10" 
     android:layout_toStartOf="@+id/timeStart" 
     android:layout_alignBottom="@+id/timeStart" /> 

    <EditText 
     android:id="@+id/timeStart" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:inputType="time" 
     android:ems="10" 
     android:layout_above="@+id/timeEnd" 
     android:layout_alignParentEnd="true" /> 

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:visibility="visible" 
     android:text="End" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@+id/dateEnd" 
     android:layout_above="@+id/ratingBar"/> 

    <EditText 
     android:id="@+id/dateEnd" 
     android:layout_width="80dp" 
     android:layout_height="wrap_content" 
     android:inputType="date" 
     android:ems="10" 
     android:layout_toStartOf="@+id/timeEnd" 
     android:layout_alignBottom="@id/timeEnd"/> 

    <EditText 
     android:id="@+id/timeEnd" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:inputType="time" 
     android:ems="10" 
     android:layout_above="@+id/ratingBar" 
     android:layout_alignParentEnd="true" /> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Save" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true"/> 

    <RatingBar 
     android:id="@+id/ratingBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true"/> 

</RelativeLayout> 
+0

Es funktioniert genau so, wie ich es erwartet habe, danke. – Gnarkkkkk

0

RelativeLayout können Sie Elemente "einer nach dem anderen" platzieren. Verwenden Sie "layoutAlignComponent" Abschnitt Ihrer Elemente in desisgner, um sie aneinander zu haften. Ich kann sehen, Sie bereits mit Ihrem android:id="@+id/textView2" versucht, wie es android:layout_above="@+id/textView3" Feld hat.

0

Zunächst müssen Sie die android:gravity="bottom" Eigenschaft aus dem übergeordneten relativen Layout entfernen, dann müssen Sie den folgenden Code fügen Sie Ihre zeigen Speichern-Button und Bewertung Leiste in der unteren

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 
     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Save" /> 

     <RatingBar 
      android:id="@+id/ratingBar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true"/> 


    </RelativeLayout> 

und dann haben Sie die weiß entfernen Farbe Eigenschaft von den Textansichten und dann danach können Sie Ihre Textansichten sehen und sie entsprechend Ihrer UI ausrichten.

0

Ändern Sie Ihr übergeordnetes Layout in einem linearen Layout. Weil RelativeLayout eine Ansicht
Gruppe ist, die untergeordnete Ansichten in relativen Positionen anzeigt. Die Position jeder Ansicht kann relativ zu gleichgeordneten Elementen angegeben werden (z. B. links von oder unter einer anderen Ansicht) oder relativ zum übergeordneten RelativeLayout-Bereich (z. B. nach unten, links oder Mitte ausgerichtet).

Ihr Bildschirm wie  [screenshot], dass nach dem Ändern der Eltern zu linear.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:orientation="vertical" 
tools:context="com.project.vincent.activityplanner.InfoPanelActivity" 
android:gravity="bottom"> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_above="@+id/textView3" 
    android:text="test" /> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_alignParentStart="true" 
    android:layout_above="@+id/dateStart" 
    android:text="test" /> 

<TextView 
    android:id="@+id/textView4" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_alignParentStart="true" 
    android:layout_above="@+id/dateStart" 
    android:layout_alignBottom="@+id/dateStart" 
    android:text="Start" /> 

<EditText 
    android:id="@+id/dateStart" 
    android:layout_width="80dp" 
    android:layout_height="wrap_content" 
    android:inputType="date" 
    android:ems="10" 
    android:layout_toStartOf="@+id/timeStart" 
    android:layout_alignBottom="@+id/timeStart" /> 

<EditText 
    android:id="@+id/timeStart" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:inputType="time" 
    android:ems="10" 
    android:layout_above="@+id/timeEnd" 
    android:layout_alignParentEnd="true" /> 

<TextView 
    android:id="@+id/textView5" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:background="@color/white" 
    android:layout_alignParentStart="true" 
    android:layout_above="@+id/dateEnd" 
    android:text="Start" /> 

<EditText 
    android:id="@+id/dateEnd" 
    android:layout_width="80dp" 
    android:layout_height="wrap_content" 
    android:inputType="date" 
    android:ems="10" 
    android:layout_toStartOf="@+id/timeEnd" 
    android:layout_alignBottom="@id/timeEnd"/> 

<EditText 
    android:id="@+id/timeEnd" 
    android:layout_width="100dp" 
    android:layout_height="wrap_content" 
    android:inputType="time" 
    android:ems="10" 
    android:layout_above="@+id/ratingBar" 
    android:layout_alignParentEnd="true" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Save" /> 

<RatingBar 
    android:id="@+id/ratingBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" /> 

+0

Meinst du Wechsel von relativ zu linear? – Gnarkkkkk

+0

Wenn Sie ein relatives Layout verwenden, sollten Sie Abhängigkeiten für ihre untergeordneten Ansichten bereitstellen. –

+0

Vielen Dank für Ihre Antwort, es kommt näher zu dem, was ich versuche zu tun. dennoch möchte ich ein element nebeneinander platzieren, ratingbar und den save button zum beispiel. Sollte ich ein relatives Layout (oder ein anderes Layout) innerhalb des linearen Layouts verwenden, um diese Zeile mit mehreren Elementen zu erstellen? – Gnarkkkkk