2014-07-04 15 views
5

Ich habe das folgende Layout, wo die Texte bearbeiten mit scheinbar keinen Grund aus dem Bildschirm geht. Ich habe versucht, ein ähnliches Problem zu finden, aber ich konnte nicht. Es sollte ein leichtes sein, aber ich habe viele Dinge ohne Glück versucht.Edit Text aus dem Bildschirm mit GridLayout

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

    <GridLayout 
     android:id="@+id/gridLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffff" 
     android:columnCount="2" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/titleTextView" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:paddingBottom="10dp" 
      android:paddingTop="10dp" 
      android:text="dsgsdgsd" 
      android:textColor="@color/red" 
      android:textStyle="bold" /> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dip" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:background="@color/red" /> 

     <TextView 
      android:id="@+id/textTitle" 
      android:layout_gravity="left" 
      android:background="#ffffff" 
      android:paddingLeft="15dp" 
      android:text="Title" 
      android:textColor="@color/grey" /> 

     <EditText 
      android:id="@+id/editTitle" 
      android:layout_gravity="right" 
      android:inputType="text"> 
     </EditText> 

     <View 
      android:layout_height="1dip" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:background="#E6E6E6" /> 

     <TextView 
      android:id="@+id/textCategory" 
      android:layout_gravity="left" 
      android:background="#ffffff" 
      android:gravity="left" 
      android:paddingLeft="15dp" 
      android:text="Category" 
      android:textColor="@color/grey" /> 

     <EditText 
      android:id="@+id/editCategory" 
      android:layout_width="225dp" 
      android:layout_gravity="right" 
      android:inputType="text" />    

     <Button 
      android:id="@+id/btnCreateAccount" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="#ffffff" 
      android:onClick="createExpense" 
      android:text="Done" 
      android:textColor="@color/red" /> 
    </GridLayout> 

Antwort

1

Ihre aktualisierten Code Check:

Ihnen fehlten einige width, height-Attribute und Sie hatten match_parent in einem früheren Element wie View verwendet, wodurch verhindert wurde, dass jedes spätere Element Platz auf dem Bildschirm erhielt.

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

    <GridLayout 
     android:id="@+id/gridLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffff" 
     android:columnCount="2" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/titleTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:paddingBottom="10dp" 
      android:paddingTop="10dp" 
      android:text="dsgsdgsd" 
      android:textColor="@color/red" 
      android:textStyle="bold" /> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="2dip" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:background="@color/red" /> 

     <TextView 
      android:id="@+id/textTitle" 
      android:layout_gravity="left" 
      android:background="#ffffff" 
      android:paddingLeft="15dp" 
      android:text="Title" 
      android:textColor="@color/grey" /> 

     <EditText 
      android:id="@+id/editTitle" 
      android:layout_gravity="right" 
      android:inputType="text" > 
     </EditText> 

     <View 
      android:layout_width="wrap_content" 
      android:layout_height="1dip" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:background="#E6E6E6" /> 

     <TextView 
      android:id="@+id/textCategory" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:background="#ffffff" 
      android:gravity="left" 
      android:paddingLeft="15dp" 
      android:text="Category" 
      android:textColor="@color/grey" /> 

     <EditText 
      android:id="@+id/editCategory" 
      android:layout_width="225dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:inputType="text" /> 

     <Button 
      android:id="@+id/btnCreateAccount" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="#ffffff" 
      android:onClick="createExpense" 
      android:text="Done" 
      android:textColor="@color/red" /> 
    </GridLayout> 

</LinearLayout> 

Die Ausgabe ohne Farbe und Hintergrund, wie es gibt mir Fehler aufgrund von Ressourcen fehlt, ist:

enter image description here

Hier können Sie sowohl Ihre edittexts in Bildschirm sehen.

+0

großartig, es hat funktioniert! Wie kann ich die Schaltfläche "Fertig" in der Mitte platzieren? Layout_gravity = center funktioniert nicht so wie es in deinem Bild zu sehen ist. – Rafag

+1

@Rafag das ist wegen seiner Paret ist Grid-Layout, wenn Sie nur diese Schaltfläche außerhalb des Grid-Layouts, wird es in der Mitte positionieren :) –

+0

jetzt gelöst? @Rafag –

0

versuchen, diese diese Hilfe sein können Sie

<GridLayout 
    android:id="@+id/gridLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" 
    android:columnCount="2" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/titleTextView" 
     android:layout_columnSpan="2" 
     android:layout_gravity="left" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:paddingBottom="10dp" 
     android:paddingTop="10dp" 
     android:text="dsgsdgsd" 
     android:textColor="@color/red" 
     android:textStyle="bold" /> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="2dip" 
     android:layout_columnSpan="2" 
     android:layout_gravity="left" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:background="@color/red" /> 

    <TableRow android:id="@+id/tableRow1" > 

     <TextView 
      android:id="@+id/textTitle" 
      android:background="#ffffff" 
      android:paddingLeft="15dp" 
      android:text="Title" 
      android:textColor="@color/grey" /> 

     <EditText 
      android:id="@+id/editTitle" 
      android:layout_width="250dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/activity_horizontal_margin" 
      android:layout_weight="1" 
      android:inputType="text" > 

      <requestFocus /> 
     </EditText> 

    </TableRow> 

    <View 
     android:layout_height="1dip" 
     android:layout_columnSpan="2" 
     android:layout_gravity="left" 
     android:background="#E6E6E6" /> 

    <TextView 
     android:id="@+id/textCategory" 
     android:layout_gravity="left" 
     android:background="#ffffff" 
     android:gravity="left" 
     android:paddingLeft="15dp" 
     android:text="Category" 
     android:textColor="@color/grey" /> 

    <EditText 
     android:id="@+id/editCategory" 
     android:layout_width="225dp" 
     android:layout_gravity="right" 
     android:inputType="text" />    

    <Button 
     android:id="@+id/btnCreateAccount" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="#ffffff" 
     android:onClick="createExpense" 
     android:text="Done" 
     android:textColor="@color/red" /> 
</GridLayout> 
0

Ändern Sie Ihre EditText Teil zu dieser:

<EditText 
     android:id="@+id/editTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:layout_gravity="center_horizontal|top" 
     android:layout_row="4" 
     android:ems="10" 
     android:inputType="text" /> 
0

Versuchen Sie diesen Weg, hoffe, dass dies Ihnen helfen wird, Ihr Problem zu lösen.

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

    <GridLayout 
     android:id="@+id/gridLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffff" 
     android:columnCount="2" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/titleTextView" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:paddingBottom="10dp" 
      android:layout_row="0" 
      android:paddingTop="10dp" 
      android:text="dsgsdgsd" 
      android:textColor="@color/red" 
      android:textStyle="bold" /> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:layout_marginLeft="20dp" 
      android:layout_row="1" 
      android:layout_marginRight="20dp" 
      android:background="@color/red" /> 

     <TextView 
      android:id="@+id/textTitle" 
      android:layout_gravity="left" 
      android:background="#ffffff" 
      android:paddingLeft="15dp" 
      android:layout_row="2" 
      android:layout_column="0" 
      android:text="Title" 
      android:textColor="@color/grey" /> 

     <EditText 
      android:id="@+id/editTitle" 
      android:layout_width="225dp" 
      android:layout_gravity="right" 
      android:layout_row="2" 
      android:layout_column="1" 
      android:inputType="text"> 
     </EditText> 

     <View 
      android:layout_height="2dp" 
      android:layout_columnSpan="2" 
      android:layout_gravity="left" 
      android:layout_row="3" 
      android:background="#E6E6E6" /> 

     <TextView 
      android:id="@+id/textCategory" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:background="#ffffff" 
      android:gravity="left" 
      android:layout_row="4" 
      android:layout_column="0" 
      android:paddingLeft="15dp" 
      android:text="Category" 
      android:textColor="@color/grey" /> 

     <EditText 
      android:id="@+id/editCategory" 
      android:layout_width="225dp" 
      android:layout_column="1" 
      android:layout_gravity="right" 
      android:layout_row="4" 
      android:inputType="text" /> 

     <Button 
      android:id="@+id/btnCreateAccount" 
      android:layout_width="match_parent" 
      android:layout_gravity="center" 
      android:background="#ffffff" 
      android:layout_row="5" 
      android:layout_columnSpan="2" 
      android:onClick="createExpense" 
      android:text="Done" 
      android:textColor="@color/red" /> 
    </GridLayout> 

</LinearLayout> 
0

Als allgemeine Bemerkung kann man nie wrap_content mit EditText verwendet, wird es immer die Inhaltsgröße nehmen und keine andere Grenzen respektieren, so kann ein Benutzer immer ein Layout sprengt einfach durch übermäßigen Eingabe von Text. Es dauerte eine Ewigkeit, bis ich diese grundlegende Beobachtung darüber, wie Android verschiedene Einschränkungen priorisiert, realisiert habe.

Wenn ein GridLayout entscheidet, dass eine Spalte innerhalb der übergeordneten Grenzen nicht passen kann, gibt es auf und liefert ein fehlerhaftes Ergebnis. Daher wird in der Regel ein GridLayout nach Bildschirmbreite gebunden, wobei die erste Spalte die Breite überschreitet wird vom Bildschirm gedrängt werden.

Wenn Sie große und kleine Eingabefelder für die Anpassung an Datengrößen haben möchten, besteht die einfachste Möglichkeit darin, Dummy-Spalten mit Gewichten zu definieren, mit denen Platz belegt oder für größere Felder überspannt werden kann.

Verwandte Themen