Hallo allerseits.Text in EditText ist nicht in der Mitte mit center-Tag
Ich habe eine Seite für meine App erstellt und eingegebene Text ist nicht in der Mitte vertikal. Es folgt ein Screenshot mit dem XML. Ich habe mit Xml-Part gespielt und habe kein Ergebnis erhalten.
Und hier ist XML Teil:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f3f2f2"
android:orientation="vertical"
android:weightSum="10.0" >
<!-- Header -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:scaleType="fitXY"
android:src="@drawable/header_half" />
</FrameLayout>
</FrameLayout>
<TextView
android:id="@+id/header_title_free_vib_xml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center"
android:text="@string/free_vibration_one_line_strg"
android:textColor="#ed1c24"
android:textSize="24dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6.0"
android:orientation="horizontal" >
<View
android:layout_width="20dp"
android:layout_height="match_parent"
android:background="#838383" />
<LinearLayout
android:id="@+id/big_body_center_edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10.0" >
<!-- Mass -->
<LinearLayout
android:id="@+id/ll_mass_xml"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_weight="2.0"
android:orientation="horizontal"
android:weightSum="100.0" >
<TextView
android:id="@+id/tv_mass_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0"
android:gravity="left|center"
android:text="@string/mass_strg"
android:textColor="#838383"
android:textSize="16dp" />
<EditText
android:id="@+id/et_mass_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="70.0"
android:background="#e7e7e7"
android:cursorVisible="false"
android:gravity="center"
android:hint="@string/mass_boundary_for_editext_strg"
android:inputType="numberDecimal"
android:textColor="#bcbcbc" />
<TextView
android:id="@+id/tv_mass_unit_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10.0"
android:background="#adadad"
android:gravity="center"
android:text="@string/cm_strg"
android:textColor="#f3f2f2"
android:textSize="10dp" />
</LinearLayout>
<!-- Stiffness -->
<LinearLayout
android:id="@+id/ll_stiffness_xml"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:layout_weight="2.0"
android:orientation="horizontal"
android:weightSum="100.0" >
<TextView
android:id="@+id/tv_stiffness_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0"
android:gravity="left|center"
android:text="@string/stiffness_strg"
android:textColor="#838383"
android:textSize="16dp" />
<EditText
android:id="@+id/et_stiffness_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="70.0"
android:background="#e7e7e7"
android:cursorVisible="false"
android:gravity="center"
android:hint="@string/mass_boundary_for_editext_strg"
android:inputType="numberDecimal"
android:textColor="#bcbcbc" />
<TextView
android:id="@+id/tv_stiffness_unit_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10.0"
android:background="#adadad"
android:gravity="center"
android:text="@string/cm_strg"
android:textColor="#f3f2f2"
android:textSize="10dp" />
</LinearLayout>
<!-- Damping -->
<LinearLayout
android:id="@+id/ll_damping_xml"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:layout_weight="2.0"
android:orientation="horizontal"
android:weightSum="100.0" >
<TextView
android:id="@+id/tv_damping_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0"
android:gravity="left|center"
android:text="@string/damping_strg"
android:textColor="#838383"
android:textSize="16dp" />
<EditText
android:id="@+id/et_damping_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="70.0"
android:background="#e7e7e7"
android:cursorVisible="false"
android:gravity="center"
android:hint="@string/damping_boundary_for_editext_strg"
android:inputType="numberDecimal"
android:textColor="#bcbcbc" />
<TextView
android:id="@+id/tv_damping_unit_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10.0"
android:background="#adadad"
android:gravity="center"
android:text="@string/cm_strg"
android:textColor="#f3f2f2"
android:textSize="10dp" />
</LinearLayout>
<!-- Boundary Conditions -->
<LinearLayout
android:id="@+id/ll_boundary_conditions_xml"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:layout_weight="4.0"
android:orientation="horizontal"
android:weightSum="100.0" >
<TextView
android:id="@+id/tv_boundary_conditions_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="20.0"
android:gravity="left|center"
android:text="@string/boundary_conditions_strg"
android:textColor="#838383"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70.0"
android:orientation="vertical"
android:weightSum="2.0" >
<EditText
android:id="@+id/et_bc_initial_velocity_xml"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:background="#e7e7e7"
android:cursorVisible="false"
android:gravity="center"
android:hint="@string/bc_inivelo_boundary_for_et_strg"
android:inputType="numberDecimal"
android:textColor="#bcbcbc" />
<EditText
android:id="@+id/et_bc_initial_displacement_xml"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1.0"
android:background="#e7e7e7"
android:cursorVisible="false"
android:gravity="center"
android:hint="@string/bc_inidis_boundary_for_et_strg"
android:inputType="numberDecimal"
android:textColor="#bcbcbc" />
</LinearLayout>
<TextView
android:id="@+id/tv_boundary_conditions_unit_xml"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10.0"
android:background="#adadad"
android:gravity="center"
android:text="@string/cm_strg"
android:textColor="#f3f2f2"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!-- END OF ALL EditTexts -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.0"
android:gravity="center" >
<ImageButton
android:id="@+id/free_vib_proceed_xml"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="center_horizontal|center"
android:background="@xml/round_circle_btn"
android:scaleType="fitXY"
android:src="@drawable/proceed" />
</LinearLayout>
</LinearLayout>
ich auch Polsterung für EditText der Verwendung haben, aber unfortunatlly funktionierte nicht.
EditText.setPadding(0, 0, 0, 0);
ich verwendet habe TextWatcher für die Größe der Hinweis zu ändern:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.four_main_free_vib);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE){
TextSize_Value_NormalText = 22;
TextSize_Value_BiggerText = 84;
ResizeHintter(et_INI_V, 84, 30);
ResizeHintter(et_INI_D, 84, 30);
ResizeHintter(et_D, 84, 48);
ResizeHintter(et_S, 84, 48);
ResizeHintter(et_M, 84, 48);
} else if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
TextSize_Value_NormalText = 16;
TextSize_Value_BiggerText = 54;
} else if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
TextSize_Value_NormalText = 12;
TextSize_Value_BiggerText = 34;
ResizeHintter(et_INI_V, 42, 14);
ResizeHintter(et_INI_DT, 42, 14);
ResizeHintter(et_D, 42, 14);
ResizeHintter(et_S, 42, 14);
ResizeHintter(et_M, 42, 14);
} else if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
TextSize_Value_NormalText = 8;
TextSize_Value_BiggerText = 22;
} else {
TextSize_Value_NormalText = 12;
TextSize_Value_BiggerText = 36;
}
}// onCreate(Bundle).
void ResizeHintter(final EditText et, final int OriginalSize, final int HintSize){
et.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
et.setTextSize(TypedValue.COMPLEX_UNIT_DIP, HintSize);
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
if(s.length() == 0){
// No entered text so will show hint
et.setTextSize(TypedValue.COMPLEX_UNIT_DIP, HintSize);
et.setPadding(0, 0, 0, 0);
} else {
et.setTextSize(TypedValue.COMPLEX_UNIT_DIP, OriginalSize);
et.setPadding(0, 0, 0, 0);
}
}
});
}
Auch gibt es ein anderes Problem mit TextWatcher. Die Regeln (groß falls sonst) funktionieren nicht für den ersten Aktivitätslauf. Es funktioniert, nachdem Sie den gesamten Text gelöscht und den Text erneut eingegeben haben. Lassen Sie sich auf den Screenshots sehen (es 2 Screenshots sind von Tablet-7" , aber vorheriger Screenshot wurde vom Handtelefon Nexus 5.
Nichts touch:
einige Ziffern eingeben:
Löschen eingegeben-Ziffern und Größe der Hinweis wie in Code sieht gut aus (big if-else):
Alle Hinweise müssen größer sein, Größe im Code erwähnt (big if-else) aber in der 1. Laufzeit bleibt es klein und nach etwas Löschen und Eingabe der Größe akzeptiert. Ich möchte den Hinweis Text-Größe wie im Code in bereitgestellt werden.
Danke.
nur überprüfen, ob 'android: layout_gravity = "center"' Sie hilft .. – Lal
@Lal bitte zumindest meinen Code zu lesen. Ich benutze das und arbeite leider nicht. tatsächlich in Tabletten (große Geräte) zentriert, aber in Nexus 5 NICHT. – SDG69