嗨大家好
我已经为我的应用程序创建了一个页面,输入的文本不是垂直中心。后面跟着XML的屏幕截图。我玩过xml的角色,但没有得到任何结果。

以下是XML部分:
<?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>我也为EditText使用了填充物,但不幸的是,它没有起作用。
EditText.setPadding(0, 0, 0, 0);我使用TextWatcher来更改提示的大小:
@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);
}
}
});
}此外,TextWatcher还有其他问题。这些规则(如果不是其他的话)不适用于第一次活动运行。它是在删除所有文本并重新输入文本之后的作品。让我们看看截图(有2个截图来自tablet-7“,但之前的截图来自手持电话,Nexus 5。
没有触碰:

输入一些数字:

删除输入的-数字和提示的大小看起来很好,在代码(大的如果-否则):

所有提示必须有更大的大小,在代码中提到(大if-否则),但在第一次运行时,它仍然很小,并在一些删除和输入的大小接受。我希望提示文本大小在提供的代码中类似。
谢谢。
发布于 2016-06-07 18:02:02
用这个:
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="start" 这是为我编辑文本的作品。
发布于 2016-06-07 18:09:00
变化
<EditText
android:layout_height="wrap_content"
/>至
<EditText
android:layout_height="match_parent"
/>https://stackoverflow.com/questions/37686064
复制相似问题