我想为视图添加笔画

时间:2018-06-06 10:06:07

标签: android

我正在尝试使用drawable为视图添加笔触。 但我想只在侧面部分(左侧和右侧)添加它,而不是整个部分。 是否有任何好的方法在侧面部分添加笔划?

下面是我的可绘制xml代码。 (leanear_border_gray.xml)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="2dp"
        android:color="#778899"/>

</shape>

及以下是我的目标视图xml代码。

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@drawable/linear_border_gray"
        android:layout_weight="1">
       ....
   </LinearLayout>

2 个答案:

答案 0 :(得分:2)

您需要将(chatenv) muiruri_samuel@train:~/webapp/chatsys$ python manage.py test chat.tests /home/muiruri_samuel/webapp/chatenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/games:/snap/bin Creating test database for alias 'default'... System check identified no issues (0 silenced). E ====================================================================== ERROR: setUpClass (chat.tests.ChatTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/muiruri_samuel/webapp/chatsys/chat/tests.py", line 17, in setUpClass cls.driver = webdriver.Firefox() File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py" , line 170, in __init__ keep_alive=True) File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__ self.start_session(capabilities, browser_profile) File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute self.error_handler.check_response(response) File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities ---------------------------------------------------------------------- Ran 0 tests in 1.012s FAILED (errors=1) Destroying test database for alias 'default'... 包裹成shape layer-list矩形,添加笔划并使用带有负值的顶部和底部边距“隐藏”顶部和底部线条,如下所示:

drawable

答案 1 :(得分:1)

您可以使用@iDemigod建议的layer-list drawable来实现

你的布局应该是这样的:

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:layout_marginTop="20dp"
    android:background="@drawable/border_left_right"
    android:layout_gravity="center"
    android:layout_weight="1">

</LinearLayout>

注意:如果您要提供android:layout_height="match_parent"android:layout_weight="1",则必须为android:layout_width="0dp"设置android:layout_width="match_parent",反之亦然。

文件: border_left_right.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-4dp" android:bottom="-4dp">
    <shape android:shape="rectangle">
        <stroke android:width="2dp" android:color="#07060b"/>
    </shape>
</item>