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