2013-03-16 10 views
7

W moim układzie znajdują się cztery sekcje odpowiednio nagłówek, edytowalna kontrolka, lista i zestaw przycisków. Chcę trzymać przyciski u dołu ekranu. Wprowadzam zbyt wiele zmian w układzie, aby zmusić przyciski do dołu. Ale nic się nie stało. Proszę podać instrukcje, aby zrobić to, co potrzebne. Jestem delegowania układ równieżsposób wyrównania zestawu przycisków do dolnej części ekranu w Androidzie

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

Odpowiedz

7

Bądź rodzicem LinearLayout zawierającego przycisk jako względny i ustaw właściwość układu liniowego zawierającego dwa przyciski jako android: layout_alignParentBottom = "true". Możesz także ustawić gęstość liniowego układu na dół.

Spróbuj tego:

<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

Take głównego rodzica jako układ względnej i dać android:layout_alignParentBottom="true" na układ przycisków ...

+0

Czy to możliwe bez zmiany układu na względny? – Riskhan

+0

spróbuj przesunąć układ przycisków poza widokiem przewijania, ale nadal musisz wziąć jeden główny układ, który będzie zawierał zarówno widok przewijania, jak i układ dolnego przycisku. –

+0

Zmieniłem mainlayout na względne i usunięte przewijanie, teraz wszystkie kontrolki nachodzą na siebie – Riskhan

2

Musisz użyć układ nadrzędny jako względny, a następnie użyć androida własności: layout_alignParentBottom = "true" do sublayout.

1

Wypróbuj ten kod przez co układ względną jako układ dominującej i Android: layout_alignParentBottom = „true” do układu przycisków

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

układ względna jest najlepszym sposobem, aby to zrobić zgodnie z sugestią Karan_Rana , ale jeśli nie chcesz używać układ względny spróbować tego:

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

Tu trzeba użyć LinearLayout jako rodzica i ustawić weightSum do niego i stosują tę samą layout_weight do układu, który chcesz w trybie pełnoekranowym. A układ, który chcesz na dole (zapisz i anuluj) zastosuj layout_weight do 0.

To działa dobrze!

0

Spróbuj tego.

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

dla przycisku wyświetlania u dołu.

Powiązane problemy