edittext的默认高度是多少?

问题描述 投票:0回答:3

在我的xml代码中,有一个微调器和edittext都将高度设置为wrap_content。但是微调器的高度小于edittext。我的目标是将两个高度都设置为相同。

我尝试将Widget.AppCompact.EditText样式应用于微调器,但无法正常工作。我目前使用Theme.AppCompat.Light.DarkActionBar作为基本主题。

android android-edittext spinner
3个回答
0
投票

要具有相同的高度,请像这样使用LinearLayoutlayout_weight

<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>

0
投票

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>

0
投票

您可以通过onCreate方法执行此操作:

© www.soinside.com 2019 - 2024. All rights reserved.