Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使编辑文本适合两个按钮?_Java_Android_Android Layout - Fatal编程技术网

Java 如何使编辑文本适合两个按钮?

Java 如何使编辑文本适合两个按钮?,java,android,android-layout,Java,Android,Android Layout,我有3个按钮,我想在它们之间创建一个文本字段, 以下是XML代码: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

我有3个按钮,我想在它们之间创建一个文本字段, 以下是XML代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/selecmain"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">


<Button
    android:id="@+id/button1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:elevation="5dp"
    android:textAlignment="center"
    android:textColor="#514e4e"
    android:textSize="20sp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginStart="50dp"
    android:layout_marginEnd="50dp" />

<Button
    android:id="@+id/button2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:textAlignment="center"
    android:textColor="#514e4e"
    android:textSize="20sp"
    android:elevation="5dp"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="@+id/button1"
    app:layout_constraintRight_toRightOf="@+id/button1"
    app:layout_constraintTop_toBottomOf="@+id/button1"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintTop_creator="1" />


<EditText
    android:id="@+id/et"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_gravity="top|center_horizontal"
    android:textSize="25sp"
    android:gravity="top|left"
    android:hint="Write something here."
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/count"
    android:maxLength="140"
    android:background="@null">
</EditText>

<TextView
    android:id="@+id/count"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="10dp"
    android:text="140/140"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/button3"
    android:layout_marginBottom="10dp" />

<Button
    android:id="@+id/button3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:elevation="5dp"
    android:onClick="setBtnRecord"
    android:text="Record"
    android:textAlignment="center"
    android:textColor="#FFFFFF"
    android:textSize="20sp"
    android:visibility="visible"
    android:enabled="false"
    android:layout_marginBottom="10dp"
    app:layout_constraintLeft_toLeftOf="@id/button2"
    app:layout_constraintRight_toRightOf="@id/button2"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="1.0" />
</android.support.constraint.ConstraintLayout>

我希望edittext填充按钮2和按钮3之间的空间,但我不能简单地将其放在按钮下方,因为我也想为edittext设置一个边界。我的意图是让用户知道,这些大区域是他们用来写东西的。 此外,我有时会使button2不可见,但我希望edittext保持与button2相同的位置

我知道这与edittext的高度有关,但我不知道如何使它适合不同的屏幕大小,甚至只适合一个大小。

试试这段代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/selecmain"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">


<Button
    android:id="@+id/button1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:elevation="5dp"
    android:textAlignment="center"
    android:textColor="#514e4e"
    android:textSize="20sp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginStart="50dp"
    android:layout_marginEnd="50dp" />

<Button
    android:id="@+id/button2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:textAlignment="center"
    android:textColor="#514e4e"
    android:textSize="20sp"
    android:elevation="5dp"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintTop_toBottomOf="@+id/button1"
    app:layout_constraintLeft_toLeftOf="@+id/button1"
    app:layout_constraintRight_toRightOf="@+id/button1"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintTop_creator="1" />


<EditText
    android:id="@+id/et"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="10dp"
    android:layout_gravity="top|center_horizontal"
    android:textSize="25sp"
    android:gravity="top|left"
    android:hint="Write something here."
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/button2"
    app:layout_constraintBottom_toTopOf="@+id/count"
    android:maxLength="140"
    android:background="@null">
</EditText>

<TextView
    android:id="@+id/count"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="10dp"
    android:text="140/140"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/button3"
    android:layout_marginBottom="10dp" />

<Button
    android:id="@+id/button3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:elevation="5dp"
    android:onClick="setBtnRecord"
    android:text="Record"
    android:textAlignment="center"
    android:textColor="#FFFFFF"
    android:textSize="20sp"
    android:visibility="visible"
    android:enabled="false"
    android:layout_marginBottom="10dp"
    app:layout_constraintLeft_toLeftOf="@+id/button1"
    app:layout_constraintRight_toRightOf="@+id/button1"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="1.0" />


感谢您的快速回复,但我甚至找不到在编辑文本中键入内容的位置。再次感谢您的回答,但我实际上在寻找不同的内容,这是我想要的硬代码版本的屏幕截图:如果您早点附加屏幕截图,效果会更好。无论如何,更新了答案抱歉mb,第一次问问题,真的很感谢你的回答,这就是我要找的。