簡體   English   中英

如何將文本框與屏幕底部的三個按鈕一起居中放置在屏幕中央?

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

我正在使用android,並且已經設計了xml,其中在屏幕底部顯示了三個按鈕。 現在,我想在屏幕中央顯示一個文本框,並在屏幕底部顯示三個按鈕。

以下是我的布局,該布局在屏幕底部顯示了三個按鈕,但在屏幕中央沒有顯示文本框-

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

以及如何像在HTML中一樣在文本框中添加占位符? 一旦我在測試框中單擊,該占位符就會消失,它們可以開始鍵入。

嘗試使用ReleativeLayout代替,然后為TextView設置名為

android:layout_centerInParent="true"

,對於三個按鈕,設置layout_alignParentBottom:

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

然后對齊與第一個相關的其他兩個按鈕。

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

使用下面的代碼,我認為它為您工作

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

我檢查了您的代碼並為您整理了代碼。 android:hint =“您的消息在這里”。 可用於在文本框中添加占位符。

`

<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