簡體   English   中英

在LinearLayout中如何在按鈕上放置EditText?

[英]How to place EditText over a button when in LinearLayout?

這是現在的樣子:

在此處輸入圖片說明

我希望它看起來像什么:

在此處輸入圖片說明

我想在按鈕內(時間會過去)有一個可編輯的文本框。 我該怎么做呢?

碼:

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

    // NAME 1
    <Button
        android:id="@+id/name1"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@drawable/button_border"
        android:text="Name"
        android:onClick="changeName"/>
    // NAME 2
    <Button
        android:id="@+id/name2"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@drawable/button_border"
        android:text="NAME"
        android:onClick="changeName"/>

</LinearLayout>

謝謝,對於這個問題的簡單性,我們深表歉意。 我只是一個嘗試學習更多知識的業余愛好者。

嘗試這種方式對您有幫助

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:background="#f0f8f0"
    android:layout_height="match_parent">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        >
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#4472C4"
            >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Liam Ten"
            android:textStyle="bold"

            android:textColor="@android:color/white"
            android:textSize="16dp"
            />
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="01:03:66"
                android:textSize="16dp"
                android:textColorHint="@android:color/white"

                />
        </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="Neil C"
            android:textSize="16dp"
            android:gravity="center"
            android:background="#4472C4"

            android:textColor="@android:color/white"
            android:layout_weight="1"
            android:textStyle="bold"
            />
    </LinearLayout>
</LinearLayout>

OUPUT

在此處輸入圖片說明

我想您正在顯示計時器的時間,該時間將經常更改。 最好使用這種方法。

String myValue = String.format("%s \n %s", "Liam Tan" , String.valueOf(yourTimingValue));

myButton.setText(myValue);

有兩種方法可以實現此目的。

name1.setText("Liam Taen" + "\n" + dateTimeString);

並在xml中將multiline=true添加到Button name1

其次,使用

<LinearLayout root layout with orientation horizontal
  <LinearLayout width weight 1 where orientation vertical
     <Button  for name >
     <TextView for showing time>
  </LinearLayout end linearLayout>

  <LinearLayout width weight 1 where orientation vertical>
       <Button name2 to center by layout_gravity= center or gravity= center from parent
  </LinearLayout end second linearlayout>

</LinearLayout end root  linearlayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM