代码之家  ›  专栏  ›  技术社区  ›  mr debug

如何在android中设置视图的底部边框

  •  0
  • mr debug  · 技术社区  · 7 年前

    我试图在Android中使用layer list drawable来设置TextView的下边框,但问题是我看到了一些从下往上的角,但在TextView下没有一条直线。我希望它是完美的直线而不是曲线。

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <!-- draw a 4 dp width border around the rectangle shape -->
                <stroke android:color="@color/colorPrimary" android:width="2dp"/>
            </shape>
        </item>
        <!--
            hide left, top and right side border using white color
            by padding 4 dp bottom side
        -->
        <item android:bottom="3dp">
            <shape android:shape="rectangle">
                <solid android:color="@android:color/white"/>
            </shape>
        </item>
    </layer-list>
    
    
    
    
      <TextView
            android:gravity="center"
            android:text="@string/eat"
            android:textSize="12sp"
            android:background="@drawable/border_bottom_green_tab"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    

    the result I am getting

    2 回复  |  直到 7 年前
        1
  •  1
  •   Faisal Naseer    7 年前

    这将适用于你只要改变3dp到1dp为

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
    
                <stroke android:color="@color/colorPrimary" android:width="2dp"/>
            </shape>
        </item>
    
        <item android:bottom="1dp">
            <shape android:shape="rectangle">
                <solid android:color="@android:color/white"/>
            </shape>
        </item>
    </layer-list>
    
        2
  •  0
  •   V-rund Puro-hit    7 年前

    只是使用 solid 而不是 stroke item

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!-- draw a 4 dp width border around the rectangle shape -->
            <solid android:color="@color/colorPrimary" />
        </shape>
    </item>
    <!--
        hide left, top and right side border using white color
        by padding 4 dp bottom side
    -->
    <item android:bottom="3dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
        </shape>
    </item>