繁体   English   中英

如何删除Linearlayout中按钮的空白

[英]How to remove blank space of button inside 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>



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

<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"以提供 webview 类似的重叠效果,但它可以满足您的要求。

您可以通过使用FramLayout包装ListViewButton来做到这一点:

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

您需要将android:layout_weight=".53"ListView移动到FrameLayout并将bottom添加到Button's android:layout_gravity

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM