首页 > 解决方案 > 如何删除Linearlayout中按钮的空白

问题描述

当我将按钮放在线性布局中时,按钮周围有空白区域。删不掉,怎么删?有一张图片。正如您在按钮左侧看到的那样,有很大的空白区域。我不想使用相对布局,因为我需要我的 webview 显示一半的屏幕大小

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>



标签: androidandroid-linearlayout

解决方案


这在线性布局中是不可能的,因此我将其展平为相对布局,请查看:

<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>

另外,我没有为您的 webview 分配固定高度,而不是给予重量。通过这样做,您还可以android:layout_above="@+id/progressBar"从 listview 中删除,以提供类似重叠效果的 webview,但它符合您的要求。


推荐阅读