为了账号安全,请及时绑定邮箱和手机立即绑定

layout_marginBottom不起作用的问题

在FrameLayout中对金币图像ImageView设置layout_marginBottom ="8dp"不会起作用,一定要加上layout_gravity = "bottom" 金币图像才会显示到底部,这是为什么??

代码如下:

<FrameLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">
   <ImageButton
       android:id="@+id/delete_imgButton"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:background="@drawable/delete_button_selector"/>
   <ImageView
       android:id="@+id/iv_delete_button"
       android:layout_width="15dp"
       android:layout_height="15dp"
       android:background="@drawable/game_coin_icon"
       android:layout_marginBottom="8dp"
       android:layout_gravity="bottom"      //  不设置这一句layout_marginBottom就不起作用
       android:layout_marginLeft="8dp"
       />
   <TextView
       android:id="@+id/tv_delete_consume_coin"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="30"
       android:textSize="12sp"
       android:textColor="@color/white"
       android:layout_gravity="bottom|right"
       android:layout_marginRight="9dp"
       android:layout_marginBottom="8dp"/>
</FrameLayout>

正在回答

1 回答

不设置gravity为bottom时,金币图标参考的锚点在左上角,这时设置marginBottom调位置是不符合逻辑的。只有设置了,将锚点改到左下角,这样逻辑才成立。

同时marginBottom为8dp不是不起作用,是起了作用你没看出来,你改个800dp试试。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android猜歌游戏是这样炼成的
  • 参与学习       27729    人
  • 解答问题       433    个

手把手教你完成一款猜歌类游戏,向你展示游戏实现的全部细节

进入课程

layout_marginBottom不起作用的问题

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号