2016-05-12 11 views
0

Wie Sie in meinem Screenshot sehen können, sind Ansichten wie ein EditText übergelaufen oder verschwunden. Aus diesem Grund kann ich die Bildlaufleiste auf der rechten Seite eines mehrzeiligen EditText nicht sehen.Ansichten sind übergelaufen oder verschwunden in Android 5

Wie kann ich das beheben? Ich habe match_parent und fill_parent versucht, kann aber keinen Unterschied sehen. 'wrap_content' ist nicht nett für ein Formular.

Screenshot Android Studio, EditText overflows

Hier ist meine xml:

<?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:orientation="vertical" 
    tools:context=".MyActivity"> 

    <GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:columnCount="2"> 

     <TextView android:text="Label for first EditText" /> 

     <EditText 
      android:id="@+id/et_id" 
      android:layout_width="match_parent" 
      android:lines="1" 
      android:maxLength="13" 
      android:maxLines="1" /> 

     <TextView android:text="Another Label for another ET" /> 

     <EditText 
      android:id="@+id/et_new_description" 
      android:layout_width="match_parent" 
      android:lines="3" 
      android:maxLines="10" 
      android:inputType="textMultiLine" 
      android:scrollbars="vertical" <!-- can't see this --> 
      android:scrollbarAlwaysDrawVerticalTrack="true"/> 

    </GridLayout> 

    <android.support.v7.widget.ButtonBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:layout_alignParentBottom="true"> 

     <Button 
      android:id="@+id/button_cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:drawableLeft="@drawable/filter" 
      android:text="cancel" /> 

     <Button 
      android:id="@+id/button_save" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:drawableLeft="@android:drawable/ic_menu_save" 
      android:text="save" /> 

    </android.support.v7.widget.ButtonBarLayout> 
</RelativeLayout> 
+0

Ihre Views brauchen sowohl 'layout_width' als auch' layout_height', zeigen Sie diese nicht oder werden sie in einem Stil oder etwas behandelt? – zgc7009

+0

Es gibt keine weiteren Attribute. – EV221

+0

@ EV221 Versuchen Sie es auf dem Gerät auszuführen. Manchmal rendert der Layout-Editor die Dinge nicht genau so, wie sie auf einem echten Gerät erscheinen. – Karakuri

Antwort

0

ich die richtige Art und Weise denken, dies zu tun mit dem android:layout_columnWeight Attribut ist. Hier ist ein Beispiel:

<GridLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="2" 
    ... > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:text="Label" 
     ... /> 

    <EditText 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_column="1" 
     android:layout_columnWeight="1" 
     ... /> 

    <!-- Same pattern for other labels and text fields --> 

</GridLayout> 

jedoch dieses Attribut nur verfügbar ist, in API beginnend 21 (Lollipop). Sie könnten die Unterstützung Version von GridLayout stattdessen verwenden, die Sie

compile 'com.android.support:gridlayout-v7:23.3.0' 

zum dependencies Block in Ihrer build.gradle Datei hinzufügen erfordert, und dann

<android.support.v7.widget.GridLayout> 

in Ihrem Layout-Datei verwenden. Das würde ich dir empfehlen.


Wenn Sie als Lollipop Versionen älter zu unterstützen, ohne auch die Unterstützung Version von Gridlayout zu verwenden, ist hier eine weitere Möglichkeit, um den gewünschten Effekt zu erreichen:

<GridLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="2" 
    ... > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:text="Label" 
     ... /> 

    <EditText 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_column="1" 
     android:layout_gravity="fill_horizontal" 
     ... /> 

    <!-- Same pattern for other labels and text fields --> 

</GridLayout> 

Sie könnten android:layout_width="wrap_content" stattdessen verwenden haben, android:layout_width="0dp" für die EditText, bin ich mir nicht sicher.

+0

Danke. Ihr zweiter Rat für ältere Versionen hat mir geholfen. Dein erster Ratschlag funktioniert nicht für mich. – EV221