2013-12-03 2 views
1

Я бы хотел, чтобы вторая позиция кнопки была ниже первой кнопки и ширины и ширины упаковки. Я уже пытаюсь относиться к макету и расположению макета, а также устанавливать силу тяжести, но все это не дает мне решение для этого ,Как установить xml-макет для кнопки

<FrameLayout 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:background="#0099cc" 
tools:context=".MainActivity" > 
<TextView 
    android:id="@+id/fullscreen_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:keepScreenOn="true" 
    android:text="Vibrate" 
    android:textColor="#33b5e5" 
    android:textSize="50sp" 
    android:textStyle="bold" /> 

<!-- 
    This FrameLayout insets its children based on system windows using 
    android:fitsSystemWindows. 

--> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" > 

    <LinearLayout 
     android:id="@+id/fullscreen_content_controls" 
     style="?buttonBarStyle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center_horizontal" 
     android:background="@color/black_overlay" 
     android:orientation="horizontal" 
     tools:ignore="UselessParent" > 

     <Button 
      android:id="@+id/btnStartService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.15" 
      android:text="@string/start_service" /> 

     <Button 
      android:id="@+id/btnStopService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/stop_service" /> 
    </LinearLayout> 
</FrameLayout> 

+0

Использование горизонтальной ориентации в LinearLayout является проблемой здесь. используйте вертикальную ориентацию, если вы хотите, чтобы вторая кнопка была ниже первой. – dm78

ответ

2

Изменение ориентации LinearLayout удалить вес, как это:

<FrameLayout 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:background="#0099cc" 
tools:context=".MainActivity" > 
<TextView 
    android:id="@+id/fullscreen_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:keepScreenOn="true" 
    android:text="Vibrate" 
    android:textColor="#33b5e5" 
    android:textSize="50sp" 
    android:textStyle="bold" /> 

<!-- 
    This FrameLayout insets its children based on system windows using 
    android:fitsSystemWindows. 

--> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" > 

    <LinearLayout 
     android:id="@+id/fullscreen_content_controls" 
     style="?buttonBarStyle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center_horizontal" 
     android:background="@color/black_overlay" 
     android:orientation="vertical" 
     tools:ignore="UselessParent" > 

     <Button 
      android:id="@+id/btnStartService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_service" /> 

     <Button 
      android:id="@+id/btnStopService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/stop_service" /> 
    </LinearLayout> 
</FrameLayout> 
-1

Используйте Relative Layout для этих двух кнопок. Во второй кнопке есть свойство, называемое «layout_below» -> Дайте идентификатор первой кнопки в этом.

Тогда ваша вторая кнопка будет опускаться ниже первой кнопки

+0

Относительная компоновка не нужна и требует дополнительных ресурсов для рендеринга. Просто используйте 'LinearLayout' с' vertical = "vertical" 'для чего-то такого простого. – dm78

+0

Мой ответ правильный. Это его желательная пшеница, которую он хочет использовать. –

+0

Ваш ответ неверен, используемые методы просто не нужны. – dm78

1

Попробуйте это .. вы ahve дали ориентациягоризонтальнаяandroid:orientation="horizontal", то он не будет опускаться ниже android:orientation="vertical"

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" > 

    <LinearLayout 
     android:id="@+id/fullscreen_content_controls" 
     style="?buttonBarStyle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center_horizontal" 
     android:background="@color/black_overlay" 
     android:orientation="vertical" 
     tools:ignore="UselessParent" > 

     <Button 
      android:id="@+id/btnStartService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_service" /> 

     <Button 
      android:id="@+id/btnStopService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/stop_service" /> 
    </LinearLayout> 
</FrameLayout> 

Для RelativeLayout использование android:layout_below="@+id/btnStartService" для второй кнопка

<RelativeLayout 
       android:id="@+id/fullscreen_content_controls" 
       style="?buttonBarStyle" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom|center_horizontal" 
       android:background="@color/black_overlay" 
       tools:ignore="UselessParent" > 

       <Button 
        android:id="@+id/btnStartService" 
        style="?buttonBarButtonStyle" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/start_service" /> 

       <Button 
        android:id="@+id/btnStopService" 
        style="?buttonBarButtonStyle" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/btnStartService" 
        android:text="@string/stop_service" /> 
      </RelativeLayout> 
0
<Button 
      android:id="@+id/btnStartService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.15" 
      android:text="@string/start_service" /> 

     <Button 
      android:id="@+id/btnStopService" 
      style="?buttonBarButtonStyle" 
      android:layout_width="0dp" 
      android:layout_below="@+id/btnStartService" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/stop_service" /> 

добавить андроид: layout_below = "@ + идентификатор/btnStartService" до нужного объекта будет выровнять.

Смежные вопросы