2013-07-04 2 views
0

Сейчас мой XML выглядит следующим образом:Android: Как добавить кнопку под кнопкой

<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="horizontal" 
> 

<EditText 
    android:id="@+id/table" 
    android:layout_weight="1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:editable="false" 
    android:hint="@string/table" 
    android:text="@string/table" 
    /> 
<Button 
    android:id="@+id/tableButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/copy" 
    android:onClick="copy"/> 



</LinearLayout> 

И я хочу, чтобы добавить кнопку прямо под моей уже созданной кнопке. Я попробовал добавить еще одну кнопку, но она просто помещает ее в одну строку. это LinearLayout? если да, то как это исправить?

EDIT: Разъяснения, я хочу, чтобы мой EditBox и Button были в одной строке, а затем еще одна EditBox и Button.

+0

Вы хотите, чтобы EditText был включен и для текущей кнопки? или все они могут быть уложены друг на друга? – LuckyMe

+0

@ LuckyMe Мне неинтересно, мне просто нужно это под ним :) –

+0

Легко, измените 'android: orientation =" horizontal "' в 'LinearLayout' на' android: orientation = "vertical" '. – LuckyMe

ответ

1

Это то, что вам нужно, то и копировать всю внутреннюю LinearLayout, чтобы добавить несколько строк:

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

    <!-- Copy from here --> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <EditText 
      android:id="@+id/table" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:editable="false" 
      android:hint="@string/table" 
      android:text="@string/table" /> 

     <Button 
      android:id="@+id/tableButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="copy" 
      android:text="@string/copy" /> 
    </LinearLayout> 
    <!-- To herel, and paste under --> 

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

     <EditText 
      android:id="@id/table" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:editable="false" 
      android:hint="@string/table" 
      android:text="@string/table" /> 

     <Button 
      android:id="@id/tableButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="copy" 
      android:text="@string/copy" /> 
    </LinearLayout> 

</LinearLayout> 

Что касается делать это с помощью кода , это только если вы не знаете, сколько вам нужно в общей сложности, в противном случае сделайте это в XML.

+0

Теперь я смущен. Я думал, что вы тоже захотите скопировать EditText. – LuckyMe

+0

Да, мне также нужны EditTexts, я немного изменил решение принятого ответа :) позвольте мне попробовать это. –

+0

Yup! Это тоже работает! Не могли бы вы это немного объяснить? Как работают вложенные макеты? Кроме того, возможно ли расширить EditBox, насколько это возможно? –

0

Попробуйте изменить

<Button 
    android:id="@+id/tableButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/copy" 
    android:onClick="copy"/> 

во что-то вроде этого

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    <Button 
     android:id="@+id/tableButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/copy" 
     android:onClick="copy"/> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     .../> 
</LinearLayout> 

Если вы хотите, чтобы первая кнопка, чтобы иметь ту же высоту, что и EditBox, то вам нужно будет использовать Tablelayout.

+0

Единственная проблема, с которой я нахожусь, это мой теперь больше не находится рядом с моим полем EditText. Я хочу, чтобы в моем EditTextbox появилась кнопка, а затем под ней другой набор. –

0

Попробуйте

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 

    <EditText 
     android:id="@+id/table" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:editable="false" 
     android:hint="@string/table" 
     android:text="@string/table" 
     /> 

    <Button 
     android:id="@+id/tableButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/table 
     android:text="@string/copy" 
     android:onClick="copy"/> 

    <Button 
     android:id="@+id/button2" 
     android:layout_below="@+id/tableButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     .../> 
</LinearLayout> 
1
<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" 
> 

<Button 
    android:id="@+id/tableButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:text="@string/copy" 
    android:onClick="copy"/> 

<EditText 
    android:id="@+id/table1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:editable="false" 
    android:layout_toLeftOf="@id/tableButton" 
    android:hint="@string/table" 
    android:text="@string/table" 
    /> 


<Button 
    android:id="@+id/secondButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/tableButton"/> 

<EditText 
    android:id="@+id/table2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:editable="false" 
    android:layout_bottom="@id/table1" 
    android:hint="@string/table" 
    android:text="@string/table" 
    /> 

</RelativeLayout> 
+0

Спасибо, это именно то, что мне нужно. –

+0

Добро пожаловать :) –

+0

Они оба хорошие ответы t.t Мне хотелось бы принять их обоих. –

0
<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    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:orientation="horizontal" > 
     <EditText 
      android:id="@+id/table" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:editable="false" 
      android:hint="@string/table" 
      android:text="@string/table" /> 
     <Button 
      android:id="@+id/tableButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="copy" 
      android:text="@string/copy" /> 
    </LinearLayout> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="copy" 
     android:text="@string/copy" /> 
    </LinearLayout>