【问题标题】:Positioning Widgets in a Specific Arrangment在特定排列中定位小部件
【发布时间】:2015-04-20 03:29:25
【问题描述】:

总的来说,我对 Android 编程很陌生,但我想知道是否有办法以特定方式排列我的小部件。基本上,我正在寻找 iOS 等效的约束,这将允许我将小部件放置在水平居中并距底部指定距离的位置:

--------------------
|                  |
|                  | 
|                  |   <- android device
|                  |
|                  |
|                  |   <- x is a button
|        x x       |
|                  |
--------------------

【问题讨论】:

    标签: android layout positioning


    【解决方案1】:

    您可以使用带有 alignParentBottom="true" 的 RelativeLayout 然后你可以在你的 relativelayout 中添加一个 padding 或者在你的按钮中添加一个边距,有点像这样。

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:orientation:"horizontal"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true" 
            android:layout_marginBottom="10dp">
    
            <Button 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"/>
            <Button 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"/>
        </LinearLayout>
    </RelativeLayout>
    

    【讨论】:

    • 这会将两个按钮居中放在彼此的顶部,并且不会将它们带到底部。
    • Ow ok 两个按钮 [已编辑]
    猜你喜欢
    • 2015-07-03
    • 2020-11-09
    • 2020-11-20
    • 2013-04-27
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    相关资源
    最近更新 更多