[英]How to remove blank space of button inside Linearlayout
When i put button inside linearlayout, there is blank space around button.当我将按钮放在线性布局中时,按钮周围有空白区域。 I cant remove it, How to remove it?
删不掉,怎么删? There is a picture.
有一张图片。 as you see on left of button there is big blank space.
正如您在按钮左侧看到的那样,有很大的空白区域。 i dont want use relative layout, because i need my webview showing half of screen size
我不想使用相对布局,因为我需要我的 webview 显示一半的屏幕尺寸
https://i.stack.imgur.com/TJIJ0.jpg https://i.stack.imgur.com/TJIJ0.jpg
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearlayoutweblist"
android:layout_above="@+id/gettitle"
android:orientation="vertical">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".53"
android:choiceMode="singleChoice"
android:listSelector="#a2aed3"
android:layout_above="@+id/progressBar" />
<Button
android:layout_width="48dp"
android:layout_height="wrap_content"
android:maxHeight="5dp"
android:minWidth="5dp"
android:visibility="visible"
android:background="@drawable/ic_highlight_off_black_24dp"
android:id="@+id/closebtn"
android:layout_gravity="right|end"
android:gravity="right|end" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_above="@+id/webviewlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_marginTop="-7dp"
android:layout_marginBottom="-7dp"
android:visibility="visible"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webviewlay"
android:visibility="visible"
android:paddingTop="1dp"
android:layout_weight=".47"
android:paddingBottom="2dp"
android:background="@drawable/topline"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/gettitle">
<WebView
android:id="@+id/arabicfont"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
This is not possible in linear layout so I've flatten this to a relative layout check this out:这在线性布局中是不可能的,因此我将其展平为相对布局,请查看:
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearlayoutweblist"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:listSelector="#a2aed3"
android:layout_above="@+id/progressBar" />
<Button
android:layout_width="48dp"
android:layout_height="wrap_content"
android:maxHeight="5dp"
android:minWidth="5dp"
android:visibility="visible"
android:background="@drawable/ic_highlight_off_black_24dp"
android:id="@+id/closebtn"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="@id/progressBar"/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_above="@+id/webviewlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_marginTop="-7dp"
android:layout_marginBottom="-7dp"
android:visibility="visible"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
/>
<WebView
android:id="@+id/webviewlay"
android:paddingTop="1dp"
android:paddingBottom="2dp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="400dp"
/>
</RelativeLayout>
Also instead of giving weight I've assigned fixed height to your webview.此外,我没有给你的 webview 分配固定高度,而不是给予重量。 And by doing this you can also remove
android:layout_above="@+id/progressBar"
from listview to give webview like over-lapping effect but its up to your requirement.通过这样做,您还可以从列表视图中删除
android:layout_above="@+id/progressBar"
以提供 webview 类似的重叠效果,但它可以满足您的要求。
You can do it by wrapping the ListView
and Button
with a FramLayout
:您可以通过使用
FramLayout
包装ListView
和Button
来做到这一点:
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearlayoutweblist"
android:layout_above="@+id/gettitle"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".53">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:listSelector="#a2aed3"
android:layout_above="@+id/progressBar" />
<Button
android:layout_width="48dp"
android:layout_height="wrap_content"
android:maxHeight="5dp"
android:minWidth="5dp"
android:visibility="visible"
android:background="@drawable/ic_highlight_off_black_24dp"
android:id="@+id/closebtn"
android:layout_gravity="right|end|bottom"
android:gravity="right|end" />
</FrameLayout>
<ProgressBar
android:id="@+id/progressBar"
android:layout_above="@+id/webviewlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_marginTop="-7dp"
android:layout_marginBottom="-7dp"
android:visibility="visible"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webviewlay"
android:visibility="visible"
android:paddingTop="1dp"
android:layout_weight=".47"
android:paddingBottom="2dp"
android:background="@drawable/topline"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/gettitle">
<WebView
android:id="@+id/arabicfont"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
You will need to move android:layout_weight=".53"
from ListView
to FrameLayout
and add bottom
to the Button's
android:layout_gravity
您需要将
android:layout_weight=".53"
从ListView
移动到FrameLayout
并将bottom
添加到Button's
android:layout_gravity
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.