简体   繁体   English

如何将文本框与屏幕底部的三个按钮一起居中放置在屏幕中央?

[英]How to center textbox at the center of the screen along with three buttons at the bottom of the screen?

I am working with android and I have designed my xml in which I am showing three buttons at the bottom of my screen. 我正在使用android,并且已经设计了xml,其中在屏幕底部显示了三个按钮。 Now I want to show a textbox at the center of my screen along with three buttons at the bottom of the screen. 现在,我想在屏幕中央显示一个文本框,并在屏幕底部显示三个按钮。

Below is my layout which shows three buttons at the bottom of the screen but it doesn't show textbox at the center of the screen - 以下是我的布局,该布局在屏幕底部显示了三个按钮,但在屏幕中央没有显示文本框-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <EditText
            android:id="@+id/edittext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/button"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="61dp"
            android:ems="10"
            android:inputType="text" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="ButtonA" />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="ButtonB" />

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="ButtonC" />
    </LinearLayout>

</LinearLayout> 

And also how do I add a placeholder in the textbox just like we do in HTML? 以及如何像在HTML中一样在文本框中添加占位符? As soon as I click in the testbox that placeholder will be gone and they can start typing. 一旦我在测试框中单击,该占位符就会消失,它们可以开始键入。

Try using ReleativeLayout instead then for the TextView you can set attribute named 尝试使用ReleativeLayout代替,然后为TextView设置名为

android:layout_centerInParent="true"

, and for three buttons , set layout_alignParentBottom : ,对于三个按钮,设置layout_alignParentBottom:

android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"

then align other two buttons related to first. 然后对齐与第一个相关的其他两个按钮。

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/edittext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignRight="@id/button3"
        android:text="ButtonA" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignRight="@id/button3"
        android:text="ButtonB" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="ButtonC"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

Use below code, i think its work for you 使用下面的代码,我认为它为您工作

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonA" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonB" />

    <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonC" />
</LinearLayout>

<EditText
    android:id="@+id/edittext"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:ems="10"
    android:hint="Your Hint Here"
    android:inputType="text" >
</EditText>

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/edittext"
    android:layout_centerHorizontal="true" />

I reviewed your code and sorted it out for you. 我检查了您的代码并为您整理了代码。 android:hint="Your Message here". android:hint =“您的消息在这里”。 can be used to add a placeholder in the textbox. 可用于在文本框中添加占位符。

` `

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <EditText
        android:id="@+id/edittext"
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:layout_alignLeft="@+id/button"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="61dp"
        android:ems="10"
        **android:hint="@string/edit_message"**
        android:inputType="text" />

</LinearLayout>



    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonA" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonB" />



        <Button
        android:id="@+id/button3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="ButtonC" />
</LinearLayout>

` `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM