Какова высота текста редактирования по умолчанию? - PullRequest
0 голосов
/ 24 октября 2019

В моем XML-коде есть один счетчик и edittext, и высота установлена ​​на wrap_content. Но высота счетчика меньше, чем текст редактирования. Моя цель - установить одинаковую высоту.

Я пытался применить стиль Widget.AppCompact.EditText к блесне, но он не работает. В настоящее время я использую Theme.AppCompat.Light.DarkActionBar в качестве базовой темы.

Ответы [ 3 ]

0 голосов
/ 24 октября 2019

Легко достичь того, что вы хотите с 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 голосов
/ 24 октября 2019

Вы можете сделать это в вашем onCreate методе:

editText.post(new Runnable() {
        @Override
        public void run() {
            ViewGroup.LayoutParams layoutParams=spinner.getLayoutParams();
            layoutParams.height=editText.getHeight();
            spinner.layoutParams=layoutParams;
        }
    });
0 голосов
/ 24 октября 2019

Чтобы иметь одинаковую высоту, используйте LinearLayout и layout_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>
...