2016-10-25 6 views
1

これは、それが今のように見えるものです:LinearLayoutでボタン上にEditTextを配置する方法は?

enter image description here

私はそれが見えるようにしたいもの:

enter image description here

私はボタンの内側にあるテキストボックスを持つようにしたいです(どこに行くのか)は編集可能です。これはどうすればいいですか?

コード:

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

おかげで、質問を簡単にするために申し訳ありません。私はもっ​​と学ぶことを試みるだけの素人です。

+1

それは別のオーバーテキスト –

+0

配置コンテンツの下に来るように、あなたは、ボタンのテキストには「\ n」は一緒に時間を追加し、テキストボックスを必要としないリニアレイアウトでは不可能です。代わりに相対レイアウトを使用する –

+0

@VivekMishraはこれまでFrameLayoutについて聞いたことがありますか?これは基本的にレイアウト全体についてです。 – k0sh

答えて

2

を使用

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

enter image description here

0

頻繁に変更されるタイマーの時間が表示されているようです。このアプローチをうまく使いましょう。

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

myButton.setText(myValue); 
0

これを達成するには2つの方法があります。

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

とxmlで、それはあなたを助けるこの方法を試してみて、

第二ボタンNAME1にmultiline=trueを追加

<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> 
関連する問題