【问题标题】:How to remove LinearLayout border in Android如何在Android中删除LinearLayout边框
【发布时间】:2017-07-18 19:23:55
【问题描述】:

我有一个 LinearLayout,它重复适配器中定义的元素。我一直在尝试删除底部边框,但没有成功。

res/drawable/rev_no_border.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:bottom="-1dp"
        android:left="-1dp"
        android:right="-1dp"
        android:top="-1dp">
        <shape android:shape="rectangle" />
    </item>

    <item
        android:bottom="-1dp"
        android:left="-1dp"
        android:right="-1dp"
        android:top="-1dp">
        <shape android:shape="rectangle" />
    </item>

    <item
        android:bottom="-1dp"
        android:left="-1dp"
        android:right="-1dp"
        android:top="-1dp">
        <shape android:shape="rectangle" />
    </item>

    <item
        android:bottom="-1dp"
        android:left="-1dp"
        android:right="-1dp"
        android:top="-1dp">
        <shape android:shape="rectangle" />
    </item>

</layer-list>

这就是我将可绘制对象附加到布局的方式:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/revObjectListingWrapper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@drawable/rev_no_border"
    android:color="@android:color/transparent" />

我没有做什么?

Vielen dank im voraus。

更新

【问题讨论】:

  • LinearLayout 默认没有边框。您确定问题不在于您附加到该布局的元素吗?你能给我们举一个这样的元素的例子吗?
  • @Program-Me-Rev 在您的帖子上附加屏幕截图
  • 张贴当前状态截图
  • 我刚刚添加了一个截图@Mahdi.Pishguy

标签: java android xml border android-linearlayout


【解决方案1】:

ListView 和 RecyclerView(我不知道您使用的是哪一个)都可以设置分隔线。基本上是在每个元素之间插入的一个小视图。

对于 ListView,你可以这样使用:

android:divider="@null"
android:dividerHeight="0dp"

RecyclerView 有点棘手,但你可以谷歌“android recyclerview remove divider”,然后有很多关于它的帖子。

【讨论】:

  • 非常感谢@Moonbloom。那很有帮助。它解决了它。
【解决方案2】:

线性布局默认不添加任何边框,如果需要添加边框则可以使用drawable .xml 文件,但布局中不需要任何边框,无需添加任何内容。正常的布局xml是

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> </LinearLayout>

【讨论】:

    【解决方案3】:
    android:divider="@null"
    
    android:dividerHeight="0dp"
    
    android:childDivider="@null"
    

    您可以在 ExanpandleListview 中使用来删除布局中的边框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 2014-07-28
      • 2020-08-04
      • 2021-10-06
      相关资源
      最近更新 更多