[英]Remove extra space of the buttons below Linear Layout
There's this extra space below the buttons, and I dont know why is it there. 按钮下方有这个额外的空间,我不知道为什么在那里。 I tried everything and looked for anyone who have had this kind of problem and sadly i found nothing.
我竭尽所能,寻找任何遇到这种问题的人,可惜我什么都没找到。 It's either I want to remove the extra space and/or lower it down perfectly aligned.
我要么要删除多余的空间和/或将其降低到完全对齐的状态。
Here's my xml file 这是我的xml文件
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/button_layout"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#262626"
android:gravity="center">
<Button
android:id="@+id/receipts_button"
android:background="@android:color/transparent"
android:drawableTop="@drawable/preview_save_icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button android:id="@+id/capture_button"
android:background="@android:color/transparent"
android:drawableTop="@drawable/preview_upload_icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button android:id="@+id/settings_button"
android:background="@android:color/transparent"
android:drawableTop="@drawable/preview_discard_icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
Is there any reason you are using a button instead of ImageView? 有什么理由要使用按钮而不是ImageView? You are using
android:drawableTop
which will position your image in the top part and leave some space in the bottom for text! 您正在使用
android:drawableTop
,它将图像放置在顶部,并在底部留出一些空间以显示文本! As you don't want text, I'ts easier to replace it with ImageView
and set the image as source. 因为您不需要文本,所以用
ImageView
替换文本并将其设置为源图像更容易。 So it will be centered on the view: 因此,它将以视图为中心:
<LinearLayout
android:id="@+id/button_layout"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#262626"
android:gravity="center">
<ImageView
android:id="@+id/receipts_button"
android:background="@android:color/transparent"
android:src="@drawable/ic_launcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView android:id="@+id/capture_button"
android:background="@android:color/transparent"
android:src="@drawable/ic_launcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView android:id="@+id/settings_button"
android:background="@android:color/transparent"
android:src="@drawable/ic_launcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
尝试一下,实际上,当您设置android:gravity =“ center”时,它属于布局本身,当您说layout_gravity时,它将应用于布局的子级。
android:layout_gravity="center_vertical"
First of all it is not a good practice to have many nested Layouts. 首先,拥有许多嵌套布局不是一个好习惯。 In your case you could remove either the LinearLayout or the RelativeLayout.
在您的情况下,您可以删除LinearLayout或RelativeLayout。 Beyond that, although it would be helpfull to post the whole xml, I would suggest removing the
android:layout_alignParentTop="true"
in the LinearLayout, and maybe adding something like: android:layout_gravity="bottom"
除此之外,尽管发布整个xml会有帮助,但我建议删除LinearLayout中的
android:layout_alignParentTop="true"
,并可能添加类似以下内容: android:layout_gravity="bottom"
android:drawableTop
attribute and give Button
image in android:background
attribute. android:drawableTop
属性,并在android:background
属性中提供Button
图像。 android:drawableTop
will position your image in the top part. android:drawableTop
会将您的图片放在顶部。 Set the layout_gravity
attribute to center_vertical
for the buttons 设置
layout_gravity
属性center_vertical
的按钮
<LinearLayout android:id="@+id/button_layout" android:layout_alignParentTop="true" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#262626" android:gravity="center"> <Button android:id="@+id/receipts_button" android:background="@drawable/preview_save_icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1"/> <Button android:id="@+id/capture_button" android:background="@drawable/preview_upload_icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1"/> <Button android:id="@+id/settings_button" android:background="@drawable/preview_discard_icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1"/> </LinearLayout>
Reason for this is correctly told by gameower . 游戏玩家正确地说明了原因 。 In addition to that, if you want to continue using
Buttons
then you just need to replace android:drawableTop
by android:drawableLeft
and you should get what you want. 除此之外,如果您要继续使用
Buttons
则只需将android:drawableTop
替换为android:drawableLeft
,您应该会得到想要的东西。
Hope that hepls. 希望帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.