2010-11-08 294 views

回答

188

其实这是可能的,尽管什么在其他的答案说来实现。如果您有FrameLayout,并且想要将子项目放在最下方,则可以使用android:layout_gravity="bottom",这将使该子项与FrameLayout的底部对齐。

我知道它的作品,因为我使用它。我知道已经晚了,但它可能会来方便别人,因为这排名前位置上的谷歌

+7

嗨byte1918,如果您认为这不是问题的正确答案,那么您应该非常欢迎 - 并且我认为这对每个人都有用 - 如果您发布了正确的解决方案。或者至少解释是什么让这是一个错误的答案。谢谢。 – lblasa 2012-09-28 16:13:24

+14

要对齐右下角,可以使用android:layout_gravity =“bottom | right” – 2013-09-23 00:13:04

+1

如果它不能立即反映在预览中,请尝试从设计选项卡中进行设置。通常工作, – yUdoDis 2015-07-15 18:31:49

-4

你不能用FrameLayout来做到这一点。

从规格:

http://developer.android.com/reference/android/widget/FrameLayout.html

“的FrameLayout被设计来阻挡屏幕显示单个项目上的一个区域,您可以将多个孩子去的FrameLayout增加,但所有的孩子都盯住屏幕左上角。“

为什么不使用RelativeLayout?

+0

我想要一个列表显示在左侧,重叠地图。哦,这可能与RelativeLayout不是吗?好,谢谢。 – 2010-11-09 03:28:08

+1

“但所有的孩子都固定在屏幕的左上方” - 不一定是屏幕的顶部,你可以将它对齐到右边,底部等等吗? – 2010-11-09 03:30:31

+0

是的,这是可能的RelativeLayout。您可以在彼此顶部布局视图。 – Juhani 2010-11-09 19:01:31

32

它可以通过RelativeLayout

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ImageView 
     android:src="@drawable/icon" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentBottom="true" /> 

</RelativeLayout> 
+1

如果在'RelativeLayout'中使用'wrap_content',这是行不通的。因为无论如何,RelativeLayout在整个屏幕上缩放。 – 2013-12-20 20:03:55

2

机器人:layout_gravity =“底”

+0

为什么我们使用重力,具体什么是 – blackHawk 2017-03-04 15:09:01

40

我也遇到了这种情况,并想出了如何使用做FrameLayout里。 以下输出由以下代码生成。

Some right-bottom aligned text showing up over an image using FrameLayout.

   <FrameLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" > 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@drawable/contactbook_icon" 
         android:layout_gravity="center" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="140" 
         android:textSize="12dp" 
         android:textColor="#FFFFFF" 
         android:layout_gravity="bottom|right" 
         android:layout_margin="15dp" /> 
       </FrameLayout> 

变化幅度值,以调整在图像的文本位置。删除保证金可能会使文本有时不在视图中。

+0

最好的答案......谢谢,解决了长久以来的谜团。 – YvesLeBorg 2017-04-08 14:35:02

12

设置已android:layout_gravity="bottom|right"工作对我来说

5

两种方法可以做到这一点:

1)使用的帧结构

android:layout_gravity="bottom|right" 

2)使用相对布局

android:layout_alignParentRight="true" 
android:layout_alignParentBottom="true" 
0

你可以添加一个不可见的TextView到FrameLayout。

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:visibility="invisible" 
     /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:orientation="horizontal"> 
     <Button 
      android:id="@+id/daily_delete_btn" 
      android:layout_width="0dp" 
      android:layout_height="50dp" 
      android:layout_weight="1" 
      android:text="DELETE" 
      android:layout_gravity="center"/> 
     <Button 
      android:id="@+id/daily_save_btn" 
      android:layout_width="0dp" 
      android:layout_height="50dp" 
      android:layout_weight="1" 
      android:text="SAVE" 
      android:layout_gravity="center"/> 
    </LinearLayout> 

0

如果您想尝试使用Java代码。你去 -

final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, 
              LayoutParams.WRAP_CONTENT); 
    yourView.setLayoutParams(params); 
    params.gravity = Gravity.BOTTOM; // set gravity