2010-09-25 8 views
20

zastanawiam się jak to możliwe, aby utworzyć przyciski paska buttom w Android,dno przycisk paska w Android

czytałem coś o tym rozwiązaniu UI, są tam wszelkie kontrole, które mogą być stosowane?

Odpowiedz

36

można zrobić coś takiego środka względnym układzie

<LinearLayout android:id="@+id/footer" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:orientation="horizontal" 
    android:layout_alignParentBottom="true" style="@android:style/ButtonBar"> 

    <Button android:id="@+id/saveButton" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1" 
     android:text="@string/menu_done" /> 

    <Button android:id="@+id/cancelButton" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="1" 
     android:text="@string/menu_cancel" /> 
</LinearLayout> 
+13

Jak używasz 'layout_weight' dla przycisków, należy ustawić' layout_width' do 0DP. – aaronsnoswell

+0

Przyciski w przyciskach są zwykle bez obramowania: http://stackoverflow.com/questions/16648768/why-buttons-in-button-bars- could-be-borderless-in-android-api-level-15 – drindt

3

można użyć FrameLayout umieścić coś w dole przez:

android: layout_gravity = "bottom | center"

Na przykład:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    > 
    <ListView 
     android:id="@+id/list1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     /> 
    <Button 
     android:id="@+id/btn_" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center" 
     android:text="OK" 
     /> 

</FrameLayout> 
7
<?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" 
> 
    <LinearLayout 
    android:id="@+id/buttonBar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    style="@android:style/ButtonBar" 
    android:gravity="center" 
    > 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:textStyle="bold" 
      android:textColor="#FFFFFF" 
      android:text="Button Bar"/> 
    </LinearLayout> 
</RelativeLayout> 

dostał go od poniższego linku bottombar

0

Najłatwiej jest dać układ liniowy zbudowany w stylu mianowicie „@android: Style/Holo.ButtonBar” lub jeśli jesteś na pre HC następnie „@ Android: styl/ButtomBar”

Jeśli zastanawiasz się, jakie atrybuty stosuje ten styl, to jest tutaj:

<style name="Holo.ButtonBar" parent="ButtonBar"> 
     <item name="android:paddingTop">0dip</item> 
     <item name="android:paddingStart">0dip</item> 
     <item name="android:paddingEnd">0dip</item> 
     <item name="android:paddingBottom">0dip</item> 
     <item name="divider">?android:attr/dividerVertical</item> 
     <item name="showDividers">middle</item> 
     <item name="dividerPadding">12dip</item> 
     <item name="background">@null</item> 
    </style> 

Uwaga, nie trzeba używać RelativeLayout w tym przypadku - jej całkowicie zbędne i jest bardziej kosztowne w zakresie operacji układania c w porównaniu do układu liniowego.

0

tworzę prosty AndroidBottomMenu View użyciu niestandardowego widoku. Jest to prosty i lekki, można łatwo skopiować do projektu

<com.toong.androidbottombar.bottommenu.BottomMenu 
    android:id="@+id/bottom_menu" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /> 

enter image description here

Powiązane problemy