Android Shape Line





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







18















I have the following code:



   <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp"/>
<size android:height="1dp" />
<solid android:color="#FFF"/>
</shape>


<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background ="@drawable/line"/>


I have two questions:




  1. Why the line is black instead white? I have tried putting it inside a ImageView but the result is the same.

  2. How can i set the opacity of the shape?










share|improve this question































    18















    I have the following code:



       <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">
    <stroke android:width="1dp"/>
    <size android:height="1dp" />
    <solid android:color="#FFF"/>
    </shape>


    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background ="@drawable/line"/>


    I have two questions:




    1. Why the line is black instead white? I have tried putting it inside a ImageView but the result is the same.

    2. How can i set the opacity of the shape?










    share|improve this question



























      18












      18








      18


      1






      I have the following code:



         <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="line">
      <stroke android:width="1dp"/>
      <size android:height="1dp" />
      <solid android:color="#FFF"/>
      </shape>


      <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background ="@drawable/line"/>


      I have two questions:




      1. Why the line is black instead white? I have tried putting it inside a ImageView but the result is the same.

      2. How can i set the opacity of the shape?










      share|improve this question
















      I have the following code:



         <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="line">
      <stroke android:width="1dp"/>
      <size android:height="1dp" />
      <solid android:color="#FFF"/>
      </shape>


      <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background ="@drawable/line"/>


      I have two questions:




      1. Why the line is black instead white? I have tried putting it inside a ImageView but the result is the same.

      2. How can i set the opacity of the shape?







      android shape






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 6 '10 at 9:32









      Janusz

      108k103279355




      108k103279355










      asked May 3 '10 at 11:34









      xger86xxger86x

      2,930105388




      2,930105388
























          3 Answers
          3






          active

          oldest

          votes


















          23














          1) In order to set the color of the line, you need to define android:color on the <stroke>. The <solid> element is for the background.



          2) You can set the opacity of the shape by using color values with an alpha layer, aka #ARGB. In your case, maybe #7FFF.






          share|improve this answer
























          • You mean #07FFFFFF.

            – Vaiden
            Apr 27 '14 at 14:15











          • @Vaiden Android supports 4-digit ARGB. In that case, it will be interpreted as #77FFFFFF.

            – Andrew T.
            Sep 2 '14 at 6:10



















          10














          The simplest example of the line for 2 density pixels with black color.
          Just save the xml in drawable folder: res/drawable/shape_black_line.xml



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


          Use LinearLayout and background to show the line.



          <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/divider">
          </LinearLayout>


          I hope this helped.






          share|improve this answer





















          • 3





            Wouldn't it be less memory consuming if we used <View>instead of LinearLayout?

            – Juan José Melero Gómez
            Dec 17 '15 at 10:04











          • Yes u can use it . As everyclass is extened from view

            – Hemant Shori
            Dec 24 '15 at 12:37



















          0














          A tricky way can be like this:



          1) Add a View where you want have a line.



          2) set android:background to a hex value that you can set both color and opacity.



          For example:



          <View
          android:layout_width="match_parent"
          android:layout_height="6dp"
          android:background="#77f27123"
          android:orientation="vertical" />





          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2757707%2fandroid-shape-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            23














            1) In order to set the color of the line, you need to define android:color on the <stroke>. The <solid> element is for the background.



            2) You can set the opacity of the shape by using color values with an alpha layer, aka #ARGB. In your case, maybe #7FFF.






            share|improve this answer
























            • You mean #07FFFFFF.

              – Vaiden
              Apr 27 '14 at 14:15











            • @Vaiden Android supports 4-digit ARGB. In that case, it will be interpreted as #77FFFFFF.

              – Andrew T.
              Sep 2 '14 at 6:10
















            23














            1) In order to set the color of the line, you need to define android:color on the <stroke>. The <solid> element is for the background.



            2) You can set the opacity of the shape by using color values with an alpha layer, aka #ARGB. In your case, maybe #7FFF.






            share|improve this answer
























            • You mean #07FFFFFF.

              – Vaiden
              Apr 27 '14 at 14:15











            • @Vaiden Android supports 4-digit ARGB. In that case, it will be interpreted as #77FFFFFF.

              – Andrew T.
              Sep 2 '14 at 6:10














            23












            23








            23







            1) In order to set the color of the line, you need to define android:color on the <stroke>. The <solid> element is for the background.



            2) You can set the opacity of the shape by using color values with an alpha layer, aka #ARGB. In your case, maybe #7FFF.






            share|improve this answer













            1) In order to set the color of the line, you need to define android:color on the <stroke>. The <solid> element is for the background.



            2) You can set the opacity of the shape by using color values with an alpha layer, aka #ARGB. In your case, maybe #7FFF.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 3 '10 at 14:11









            Daniel LewDaniel Lew

            67.5k26167169




            67.5k26167169













            • You mean #07FFFFFF.

              – Vaiden
              Apr 27 '14 at 14:15











            • @Vaiden Android supports 4-digit ARGB. In that case, it will be interpreted as #77FFFFFF.

              – Andrew T.
              Sep 2 '14 at 6:10



















            • You mean #07FFFFFF.

              – Vaiden
              Apr 27 '14 at 14:15











            • @Vaiden Android supports 4-digit ARGB. In that case, it will be interpreted as #77FFFFFF.

              – Andrew T.
              Sep 2 '14 at 6:10

















            You mean #07FFFFFF.

            – Vaiden
            Apr 27 '14 at 14:15





            You mean #07FFFFFF.

            – Vaiden
            Apr 27 '14 at 14:15













            @Vaiden Android supports 4-digit ARGB. In that case, it will be interpreted as #77FFFFFF.

            – Andrew T.
            Sep 2 '14 at 6:10





            @Vaiden Android supports 4-digit ARGB. In that case, it will be interpreted as #77FFFFFF.

            – Andrew T.
            Sep 2 '14 at 6:10













            10














            The simplest example of the line for 2 density pixels with black color.
            Just save the xml in drawable folder: res/drawable/shape_black_line.xml



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


            Use LinearLayout and background to show the line.



            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider">
            </LinearLayout>


            I hope this helped.






            share|improve this answer





















            • 3





              Wouldn't it be less memory consuming if we used <View>instead of LinearLayout?

              – Juan José Melero Gómez
              Dec 17 '15 at 10:04











            • Yes u can use it . As everyclass is extened from view

              – Hemant Shori
              Dec 24 '15 at 12:37
















            10














            The simplest example of the line for 2 density pixels with black color.
            Just save the xml in drawable folder: res/drawable/shape_black_line.xml



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


            Use LinearLayout and background to show the line.



            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider">
            </LinearLayout>


            I hope this helped.






            share|improve this answer





















            • 3





              Wouldn't it be less memory consuming if we used <View>instead of LinearLayout?

              – Juan José Melero Gómez
              Dec 17 '15 at 10:04











            • Yes u can use it . As everyclass is extened from view

              – Hemant Shori
              Dec 24 '15 at 12:37














            10












            10








            10







            The simplest example of the line for 2 density pixels with black color.
            Just save the xml in drawable folder: res/drawable/shape_black_line.xml



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


            Use LinearLayout and background to show the line.



            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider">
            </LinearLayout>


            I hope this helped.






            share|improve this answer















            The simplest example of the line for 2 density pixels with black color.
            Just save the xml in drawable folder: res/drawable/shape_black_line.xml



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


            Use LinearLayout and background to show the line.



            <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider">
            </LinearLayout>


            I hope this helped.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 17 '15 at 10:51









            Juan José Melero Gómez

            2,32811329




            2,32811329










            answered Sep 2 '14 at 5:14









            Hemant ShoriHemant Shori

            1,9271319




            1,9271319








            • 3





              Wouldn't it be less memory consuming if we used <View>instead of LinearLayout?

              – Juan José Melero Gómez
              Dec 17 '15 at 10:04











            • Yes u can use it . As everyclass is extened from view

              – Hemant Shori
              Dec 24 '15 at 12:37














            • 3





              Wouldn't it be less memory consuming if we used <View>instead of LinearLayout?

              – Juan José Melero Gómez
              Dec 17 '15 at 10:04











            • Yes u can use it . As everyclass is extened from view

              – Hemant Shori
              Dec 24 '15 at 12:37








            3




            3





            Wouldn't it be less memory consuming if we used <View>instead of LinearLayout?

            – Juan José Melero Gómez
            Dec 17 '15 at 10:04





            Wouldn't it be less memory consuming if we used <View>instead of LinearLayout?

            – Juan José Melero Gómez
            Dec 17 '15 at 10:04













            Yes u can use it . As everyclass is extened from view

            – Hemant Shori
            Dec 24 '15 at 12:37





            Yes u can use it . As everyclass is extened from view

            – Hemant Shori
            Dec 24 '15 at 12:37











            0














            A tricky way can be like this:



            1) Add a View where you want have a line.



            2) set android:background to a hex value that you can set both color and opacity.



            For example:



            <View
            android:layout_width="match_parent"
            android:layout_height="6dp"
            android:background="#77f27123"
            android:orientation="vertical" />





            share|improve this answer






























              0














              A tricky way can be like this:



              1) Add a View where you want have a line.



              2) set android:background to a hex value that you can set both color and opacity.



              For example:



              <View
              android:layout_width="match_parent"
              android:layout_height="6dp"
              android:background="#77f27123"
              android:orientation="vertical" />





              share|improve this answer




























                0












                0








                0







                A tricky way can be like this:



                1) Add a View where you want have a line.



                2) set android:background to a hex value that you can set both color and opacity.



                For example:



                <View
                android:layout_width="match_parent"
                android:layout_height="6dp"
                android:background="#77f27123"
                android:orientation="vertical" />





                share|improve this answer















                A tricky way can be like this:



                1) Add a View where you want have a line.



                2) set android:background to a hex value that you can set both color and opacity.



                For example:



                <View
                android:layout_width="match_parent"
                android:layout_height="6dp"
                android:background="#77f27123"
                android:orientation="vertical" />






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 24 '18 at 11:49

























                answered Nov 24 '18 at 7:06









                Kaaveh MohamediKaaveh Mohamedi

                4228




                4228






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2757707%2fandroid-shape-line%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()