Android edittext的默认高度是多少?
在我的xml代码中,一个微调器和edittext的高度都设置为Android edittext的默认高度是多少?,android,android-edittext,spinner,Android,Android Edittext,Spinner,在我的xml代码中,一个微调器和edittext的高度都设置为wrap\u content。但是微调器高度小于edittext。我的目标是将两个高度设置为相同 我试图将Widget.AppCompact.EditText样式应用于微调器,但它不起作用。我目前使用主题.AppCompat.Light.darkaActionBar作为基本主题。要具有相同的高度,请使用线性布局和布局_权重: <LinearLayout android:layout_width="match_parent
wrap\u content
。但是微调器高度小于edittext。我的目标是将两个高度设置为相同
我试图将
Widget.AppCompact.EditText
样式应用于微调器,但它不起作用。我目前使用主题.AppCompat.Light.darkaActionBar
作为基本主题。要具有相同的高度,请使用线性布局
和布局_权重
:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
使用
ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edit_text"
android:layout_width="200dp" // Change to what width you prefer
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@id/edit_text"
app:layout_constraintBottom_toBottomOf="@id/edit_text"
app:layout_constraintStart_toEndOf="@id/edit_text"/>
</androidx.constraintlayout.widget.ConstraintLayout>
您可以在
onCreate
方法中执行此操作:
editText.post(new Runnable() {
@Override
public void run() {
ViewGroup.LayoutParams layoutParams=spinner.getLayoutParams();
layoutParams.height=editText.getHeight();
spinner.layoutParams=layoutParams;
}
});
我正在使用edittext和spinner作为背景,但它们看起来不一样。它占据了半个屏幕。。我只想将默认的edittext高度设置为spinnerThanx,使其工作正常。。有什么方法可以通过xml实现吗?好吧,如果您想用xml实现,那么就给两者(EditText和spinner)指定固定高度。