【问题标题】:how to make the position of button fixed in android?如何在android中固定按钮的位置?
【发布时间】:2011-07-02 04:56:04
【问题描述】:

我有一个按钮和这个按钮上方的展开列表,当列表展开时,它下面的按钮会消失。如何使这个按钮在固定位置?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
<include layout="@layout/ads_bar" ></include>        
<TextView 
                android:text="Level 1:"
                android:textSize="20dp"
                android:id="@+id/TextView01" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"></TextView>

<TextView 
                android:text="lorem ispum something about this level ..... :)"
                android:textSize="16dp"
                android:id="@+id/TextView01" 
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"></TextView>

<ExpandableListView 
                android:id="@+id/listView"
                android:scrollbars="vertical"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"></ExpandableListView>

<include 
                android:layout_alignParentBottom="true"
                layout="@layout/quick_links_bar"></include>
</LinearLayout>

quick_links_bar 代表按钮!

【问题讨论】:

    标签: android


    【解决方案1】:

    要使按钮与底部对齐,最好使用线性布局的 layout_weight 属性。

    简单示例:

    <LinearLayout>
    
       <TextView layout_weight=1/>
       <Button layout_height="wrap_content"/>
    
    <LinearLayout>
    

    这比使用 RElative 布局要好,因为如果使用一种布局,文本的底部会被按钮截断,但在这种情况下不会发生。

    【讨论】:

      【解决方案2】:

      听起来您希望quick_links_bar 布局始终位于底部?为此,您需要使用 RelativeLayout

      将您的整个布局包装在一个 RelativeLayout 中,并将您的快速链接栏布局移到 LinearLayout 之外,并在其上设置属性 android:layout_alignParentBottom="true"。接下来,您需要为快速链接栏分配一个 ID。在您的 LinearLayout 上,设置属性 android:layout_above="@id/quicklinksbarid"。确保您的快速链接栏包含语句位于 LinearLayout 上方。

      【讨论】:

        猜你喜欢
        • 2012-12-29
        • 1970-01-01
        • 2012-10-17
        • 2020-03-30
        • 1970-01-01
        • 2014-10-30
        • 2020-01-28
        • 2011-09-25
        • 2021-01-29
        相关资源
        最近更新 更多