如何对齐一组按钮,在Android的屏幕下方 [英] how to align a set of button to bottom of the screen in android

查看:190
本文介绍了如何对齐一组按钮,在Android的屏幕下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的布局有四个部分分别是头,可编辑控制,列表和一组按钮。我想保持屏幕的按键底部。我做布局太多的变化,迫使按钮底部。但是什么都没有发生。请提供指导,使我需要的东西。我张贴的布局也

In my layout there are four sections respectively a header, an editable control, a list and a set of button. I want to keep the buttons bottom of the screen. I make too many changes in the layout to force the buttons to bottom. But nothing happened. Please provide instructions to make what i needed. I am posting the layout also

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

推荐答案

请包含按钮相对的LinearLayout的父母和设置包含两个按钮,由于Android的线性布局的属性:layout_alignParentBottom =真。您也可以线性布局的重心设置为底部。

Make the Parent of the LinearLayout containing the button as relative and set the property of linear layout containing two buttons as android:layout_alignParentBottom="true". You can also set the gravity of the Linear Layout to Bottom.

试试这个:


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

这篇关于如何对齐一组按钮,在Android的屏幕下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆