2010-09-25 2 views
20

мне интересно, как это возможно, чтобы создать днище кнопки панели в андроида,Нижняя панель кнопок в андроида

Я читал кое-что об этом решении UI, есть какие-либо элементы управления, которые могут быть использованы?

ответ

36

Вы можете сделать что-то вроде этого в относительной макете

<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

Как вы используете 'layout_weight' для кнопок, вы должны установить' layout_width' в 0dp. – aaronsnoswell

+0

Кнопки в барах кнопок обычно не имеют границ: http://stackoverflow.com/questions/16648768/why-buttons-in-button-bars-should-be-borderless-in-android-api-level-15 – drindt

3

Вы можете использовать FrameLayout положить что-то в донизу:

андроида: layout_gravity = «нижний | центр»

Например:

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

получил его по следующей ссылке bottombar

0

Самый простой способ дать ваш линейный макет построен в стиле «а именно @android: стиль/Holo.ButtonBar» или если вы на предварительно HC затем «@ Android: стиль/ButtomBar»

Если вы хотите знать, какие атрибуты применяет этот стиль, вот оно:

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

Обратите внимание, что вам не нужно использовать RelativeLayout в данном случае - его полностью избыточным и более дорогостоящие с точки зрения операций компоновки c по сравнению с линейной компоновкой.

0

Я создаю простой AndroidBottomMenu View с помощью настраиваемого представления. Это простой и легкий, вы можете легко скопировать в свой проект

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

enter image description here

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