2017-02-09 1 views
0

J'ai une disposition de table avec 2 EditText dans les 2 premières lignes, et un tas de boutons fonctionnant comme un clavier personnalisé dans les autres rangées. (juste inclus seulement la première rangée de boutons dans le xml ci-dessous pour la simplicité) Les vues d'EditText sont définies comme défilement avec android:scrollbars="vertical". Quand j'appuie sur un bouton de mon clavier personnalisé, j'ajoute la valeur à une chaîne d'entrée, puis je règle le texte avec la méthode EditText.setText(). Mon problème est que si le texte est trop long, il passe à la ligne suivante en redimensionnant la vue EditText complète aussi. Sinon, faire la même chose avec le clavier android par défaut fonctionne comme un charme, aller sur la ligne suivante sans redimensionner et afficher la barre de défilement sur la droite.

Voici le XMLEditText redimensionnement de l'affichage lors de l'utilisation de "setText" au lieu de l'entrée au clavier

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:scrollbars="vertical" 
      android:layout_height="match_parent" 
      android:id="@+id/input" 
      android:layout_span="2" 
      android:text="Type an expression to begin..." /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" 
      android:id="@+id/output" 
      android:layout_span="2" 
      android:text="Real time calculation"/> 
    </TableRow> 

    <View 
     android:layout_height="2dip" 
     android:background="#FF0000" /> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dp" > 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_clear" 
      android:text="C" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_divide" 
      android:text="/" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_multiply" 
      android:text="*" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_delete" 
      android:text="DEL" /> 
    </TableRow> 

</TableLayout> 

Quel est le problème avec la méthode setText()? En outre, je veux ajouter une image d'arrière-plan à la fois EditText redimensionner pour s'adapter à la vue sans faire EditText redimensionner.

Toutes les suggestions seront appréciés

+0

Ajouter image de sortie désirée –

Répondre

1
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_gravity="center" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:id="@+id/input" 
      android:text="Type an expression to begin...\n\n\n\n\n\n\n\n\n ddfsfs\n\n\n erwr dsf" /> 
    </ScrollView> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="2dip" 
     android:background="#220000" /> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_gravity="center" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:id="@+id/output" 
      android:text="Real time calculation"/> 
    </ScrollView> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="2dip" 
     android:background="#FF0000" /> 

    <LinearLayout 
     android:id="@+id/tableRow3" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:padding="15dp" 
      android:layout_height="match_parent" 
      android:id="@+id/button_clear" 
      android:text="C" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_divide" 
      android:text="/" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_multiply" 
      android:text="*" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/ic_cross" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_delete" 
      android:text="DEL" /> 
    </LinearLayout> 

</LinearLayout> 
+0

Merci monsieur. Tu as fait ma journée. Pouvez-vous m'expliquer pourquoi je n'aurais pas utilisé TableLayout de LinearLayout? – Razinar

0
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:scrollbars="vertical" 
      android:layout_height="match_parent" 
      android:id="@+id/input" 
      android:layout_span="2" 
      android:maxLines="1" 
      android:lines="1" 
      android:inputType="text" 
      android:text="Type an expression to begin..." /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dip"> 

     <EditText 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" 
      android:id="@+id/output" 
      android:layout_span="2" 
      android:maxLines="1" 
      android:lines="1" 
      android:inputType="text" 
      android:text="Real time calculation"/> 
    </TableRow> 

    <View 
     android:layout_height="2dip" 
     android:background="#FF0000" /> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="0dp" > 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_clear" 
      android:text="C" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_divide" 
      android:text="/" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_multiply" 
      android:text="*" /> 

     <Button 
      android:layout_width="0dp" 
      android:minHeight="0dp" 
      android:minWidth="0dp" 
      android:background="@drawable/button_custom_bg" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:id="@+id/button_delete" 
      android:text="DEL" /> 
    </TableRow> 

</TableLayout> 

Utilisez ce résoudra votre problème.