J'ai tendance à créer i superposition un Voici comment ils ressemblent à ce jour. P> Ceci est le XML utilisé p> Toutefois, lorsqu'il est livré avec Ceci est le XML utilisé P> textview code> et
editext code>, qui ressemble beaucoup à un pixel identique.
eittext code> avec
TextView code>, afin que je puisse comparer leur identique. Je fais
textview code> avoir du texte de couleur rouge. P>
edittext code> et
et
TextView code> identique sans
Android: LinesPacingMultiplier CODE> H2>
Android: LinesPacingMultiplier code>, les deux se comporte différemment. P>
editext et
textview code> est différent avec
Android: LunettesPacingMultiplier Code> H2>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/body_text_view"
android:gravity="top"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginBottom="12dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:textSize="24sp"
android:singleLine="false"
android:textColor="#ff0000"
android:lineSpacingMultiplier="2.4" />
<EditText
android:id="@+id/body_edit_text"
android:gravity="top"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginBottom="12dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:scrollbars="vertical"
android:textSize="24sp"
android:singleLine="false"
android:inputType="textMultiLine|textCapSentences"
android:lineSpacingMultiplier="2.4" />
</FrameLayout>
5 Réponses :
au lieu d'utiliser i a été capable de reproduire votre problème sur ma machine, et bien Cependant, lorsque je l'ai changé en pare-lit code> LinesPacingextra code>, par exemple: Donc, vous pouvez calculer l'espacement souhaité que vous souhaitez pour votre Cette approche a fonctionné pour moi, même lorsque j'ai joué avec le C'est le XML I ende d UP UTILISATION: P> lingepacingMultiplier code>, utilisez
lignesPacingextra CODE> et simplement c alcuber avec le multiplicateur fort> que vous souhaitez appliquer dans le code.
lingepacingMultiplier code> produit le même problème que vous aviez confronté et que vous ne trouviez aucune solution / raison pour laquelle cela se produirait (pas même sur les docs Android) strong>. p>
LunettesPacingextra = 20DP code>,
editext code> et
textview , et appliquez cette valeur via le code comme celui-ci: p>
Calculévalue code>, Le texte de Les deux éléments sont toujours parfaitement alignés. strong> p>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/body_text_view"
android:gravity="top"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginBottom="12dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:textSize="24sp"
android:singleLine="false"
android:textColor="#ff0000"
android:lineSpacingExtra="0dp"/>
<EditText
android:id="@+id/body_edit_text"
android:gravity="top"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginBottom="12dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:scrollbars="vertical"
android:textSize="24sp"
android:singleLine="false"
android:inputType="textMultiLine|textCapSentences"
android:lineSpacingExtra="0dp"/>
</FrameLayout>
lineSpacingExtra with 2dp worked fine for me but I was wondering what the Multiplier does instead?`<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:lineSpacingMultiplier="1.5" android:text="An editable text view that shows completion suggestions ... When you define an edit text widget, you must specify the R.styleable. .... android:lineSpacingMultiplier" android:id="@+id/body_text_view" android:gravity="top" android:paddingLeft="16dp" android:paddingRight="16dp" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:textSize="24sp" android:singleLine="false" android:textColor="#ff0000" /> <EditText android:lineSpacingMultiplier="1.5" android:text="An editable text view that shows completion suggestions ... When you define an edit text widget, you must specify the R.styleable. .... android:lineSpacingMultiplier" android:gravity="top" android:paddingLeft="16dp" android:paddingRight="16dp" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:textSize="24sp" android:singleLine="false" android:textColor="#000000" /> </FrameLayout> </android.support.constraint.ConstraintLayout>` 2nd way Not android:lineSpacingMultiplier=" " use LineSpacingExtra insteed LineSpacingMultiplier android:lineSpacingExtra="1.5dp" <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:lineSpacingExtra="1.5dp" android:text="An editable text view that shows completion suggestions ... When you define an edit text widget, you must specify the R.styleable. .... android:lineSpacingMultiplier DD" android:id="@+id/body_text_view" android:gravity="top" android:paddingLeft="16dp" android:paddingRight="16dp" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:textSize="24sp" android:singleLine="false" android:textColor="#ff0000" /> <EditText android:lineSpacingExtra="1.5dp" android:text="An editable text view that shows completion suggestions ... When you define an edit text widget, you must specify the R.styleable. .... android:lineSpacingMultiplier D" android:gravity="top" android:paddingLeft="16dp" android:paddingRight="16dp" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:textSize="24sp" android:singleLine="false" android:textColor="#000000" /> </FrameLayout> </android.support.constraint.ConstraintLayout>
Curieusement, ajouter
android:editable="true"
Votre solution (paramètre Android: INPUTTYPE = "TextMultiline" code>) fonctionne bien dans le réglage verticalement, mais surprenant le texte peut
Le problème était surprenant en premier lieu (en considérant un eittext code> est plus ou moins un
textview code> avec un autre thème), mais c'est juste bizarre
comme indiqué dans ce document (classe TextView Classe). P> Android: éditable fort> p>
Si défini, spécifie que ce TextView a une méthode de saisie. Ce sera un textuel à moins d'avoir été spécifié autrement. Pour TextView, c'est Cet attribut a été obsolète mais il peut être remplacé par P> Android: InputType strong> p>
Le type de données placé dans un champ de texte, utilisé pour aider une méthode de saisie décider comment laisser l'utilisateur entrer du texte. Les constantes correspondent ici à celles définies par INPUTTYPE. Généralement, vous pouvez sélectionner une seule valeur, bien que certains puissent être combinés ensemble comme indiqué. Réglage de cet attribut à tout ce que aucun em> implique également que le texte est modifiable. strong> p>
blockQuote> Pour le faire fonctionner efficacement utiliser Android: Breakstrategy strong> p>
Définit la stratégie de pause pour casser des paragraphes dans des lignes. La valeur par défaut pour textview est layout.break_strategy_high_quality, et la valeur par défaut pour editext est layout.break_strategy_simple, ce dernier pour éviter le texte "danse" lors de la modification. P>
blockQuote> en un mot "/ fort>, ajout p> au eittext code> est une extension (sous-classe) de
textview code>, mais les deux se comportent différemment ici et que cela est certainement
Compte tenu de textview code>.
TextMultiline code> parce que votre
eittext code> a la même propriété. P>
textview code> les placera exactement à la même position. p> p>
Appliquez les 2 suivants dans TextView code> résout mon problème
android:breakStrategy="simple"
android:textIsSelectable="true"
Pourquoi n'utilisez-vous pas les deux
eittext code> et faire le premier
eittext code>
android: Foncable = "FALSE" CODE>
Rendre
Android: FocestABLE = "FALSE" CODE> ne fera pas
eitText code> Comportez 100% comme
TextView code>. Je ne me souviens pas des détails exacts. Mais croyez-moi, j'ai essayé d'innombrables temps et ça ne se comporte sûrement pas comme
textview code>.
Le
eittext code> est une sous-classe de
textview code> - à l'exception de l'édition, ce qui s'applique à
textview code> s'applique à
éditext code> . Stackoverflow.com/q/4989545/76666442