2013-03-16 5 views
7

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

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

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

     <!-- heading for basic settings --> 
     <TextView 
      android:id="@+id/setup_macroheading" 
      style="@style/txtHeading" /> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="20dp"/> 

     <!-- macro name --> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="20dp" 
      android:paddingRight="20dp" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_weight="1" 
       android:textColor="@color/white"      
       android:text="Macro Name"/> 

      <EditText 
       android:id="@+id/setup_macroname" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:layout_weight="1" 
       android:maxLength="12" 
       android:inputType="textCapCharacters" 
       android:singleLine="true"/>     
     </LinearLayout> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="20dp"/> 

     <ListView 
      android:id="@+id/lvMacroList" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
     /> 

     <!-- Save & Cancel button --> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="20dp" 
      android:paddingRight="20dp" 
      android:layout_gravity="bottom" 
      android:orientation="horizontal"> 

      <Button 
       android:id="@+id/setup_macroSavebtn" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left" 
       android:layout_weight="1" 
       android:onClick="onSaveButtonClick" 
       android:text="Save"/> 

      <Button 
       android:id="@+id/setup_macroCancelbtn" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:layout_weight="1" 
       android:onClick="onCancelButtonClick" 
       android:text="Cancel"/>   
     </LinearLayout> 
    </LinearLayout> 
    </ScrollView> 

enter image description here

ответ

7

Сделать Родитель из LinearLayout, содержащего кнопку как относительный и установить свойство линейного макета, содержащего две кнопки в качестве андроида: layout_alignParentBottom = "true". Вы также можете установить гравитацию линейного макета в нижний.

Попробуйте это:

<RelativeLayout 
    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="vertical"> 
    <!-- heading for basic settings --> 
    <TextView 
     android:id="@+id/setup_macroheading" 
     style="@style/txtHeading" /> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="20dp"/> 

    <!-- macro name --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" 
     android:orientation="horizontal"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left|center_vertical" 
      android:layout_weight="1" 
      android:textColor="@color/white"      
      android:text="Macro Name"/> 

     <EditText 
      android:id="@+id/setup_macroname" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:maxLength="12" 
      android:inputType="textCapCharacters" 
      android:singleLine="true"/>     
    </LinearLayout> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="20dp"/> 

    <ListView 
     android:id="@+id/lvMacroList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
    /> 
</LinearLayout> 
    <!-- Save & Cancel button --> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     android:orientation="horizontal" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" > 

     <Button 
      android:id="@+id/setup_macroSavebtn" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_weight="1" 
      android:onClick="onSaveButtonClick" 
      android:text="Save"/> 

     <Button 
      android:id="@+id/setup_macroCancelbtn" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:onClick="onCancelButtonClick" 
      android:text="Cancel"/>   
    </LinearLayout> 
</RelativeLayout> 

6

Возьмите основной родитель, как Relative расположение и дать android:layout_alignParentBottom="true" раскладке кнопок ...

+0

Возможно ли это без изменения формата относительно? – Riskhan

+0

попробуйте переместить макет кнопки за пределы прокрутки, но все же вам нужно взять один основной макет realtive, который будет содержать как прокрутку, так и нижнюю компоновку кнопок. –

+0

Я изменил mainlayout на относительный и удаленный scrollview, теперь все элементы управления перекрываются друг с другом – Riskhan

2

Вы должны использовать родительское расположение, как относительные, а затем использовать свойство андроида: layout_alignParentBottom = "истинный" в sublayout.

1

Попробуйте этот код, делая относительное расположение в качестве родительского макета и Android: layout_alignParentBottom = «истина» в макете кнопку

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 

<!-- heading for basic settings --> 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="20dp" /> 

     <!-- macro name --> 

     <LinearLayout 
      android:id="@+id/llTop" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:paddingLeft="20dp" 
      android:paddingRight="20dp" > 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="left|center_vertical" 
       android:layout_weight="1" 
       android:text="Macro Name" /> 

      <EditText 
       android:id="@+id/setup_macroname" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:layout_weight="1" 
       android:inputType="textCapCharacters" 
       android:maxLength="12" 
       android:singleLine="true" /> 
     </LinearLayout> 

     <!-- Save & Cancel button --> 

    </RelativeLayout> 
</ScrollView> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:orientation="horizontal" 
    android:paddingLeft="20dp" 
    android:paddingRight="20dp" > 

    <Button 
     android:id="@+id/setup_macroSavebtn" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_weight="1" 
     android:onClick="onSaveButtonClick" 
     android:text="Save" /> 

    <Button 
     android:id="@+id/setup_macroCancelbtn" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:layout_weight="1" 
     android:onClick="onCancelButtonClick" 
     android:text="Cancel" /> 
</LinearLayout> 

2

Относительное расположение является лучшим способом сделать это как это было предложено Karan_Rana , но если вы не хотите использовать относительное расположение попробовать это один:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <!-- heading for basic settings --> 
    <TextView 
     android:id="@+id/setup_macroheading" 
     android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
     /> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="20dp"/> 

    <!-- macro name --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" 
     android:orientation="horizontal"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left|center_vertical" 
      android:layout_weight="1" 
      android:textColor="@color/white"      
      android:text="Macro Name"/> 

     <EditText 
      android:id="@+id/setup_macroname" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:maxLength="12" 
      android:inputType="textCapCharacters" 
      android:singleLine="true"/>     
    </LinearLayout> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="20dp"/> 

    <ListView 
     android:id="@+id/lvMacroList" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

</LinearLayout> 
</ScrollView> 

<!-- Save & Cancel button --> 
     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" 
     android:layout_weight="0" 
     android:layout_gravity="bottom" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/setup_macroSavebtn" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_weight="1" 
      android:onClick="onSaveButtonClick" 
      android:text="Save"/> 

     <Button 
      android:id="@+id/setup_macroCancelbtn" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:onClick="onCancelButtonClick" 
      android:text="Cancel"/>   
    </LinearLayout> 

Здесь вам нужно использовать LinearLayout в качестве родителя и установить weightSum к нему и применить тот же layout_weight к раскладке вы хотите в полноэкранном режиме. И макет, который вы хотите в нижней части (сохранить и отменить), примените layout_weight к 0.

Это хорошо работает!

0

попробуйте это.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    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_alignParentRight="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentBottom="true" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_marginRight="2dp" 
      android:text="Modify" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_marginRight="2dp" 
      android:text="Cancle" /> 

    </LinearLayout> 

</RelativeLayout> 

для отображения кнопки внизу.

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