Android 形状线

发布于 2024-08-31 03:07:17 字数 527 浏览 3 评论 0原文

我有以下代码:

   <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"/>

我有两个问题:

  1. 为什么线条是黑色而不是白色?我尝试将其放入 ImageView 但结果是相同的。
  2. 如何设置形状的不透明度?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟织青萝梦 2024-09-07 03:07:17

1)为了设置线条的颜色,您需要定义 android:color< <笔划> 上的 /code>元素用于背景。

2)您可以使用 带有 alpha 层的颜色值,又名#ARGB。就你而言,也许#7FFF。

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.

自我难过 2024-09-07 03:07:17

最简单的黑色 2 密度像素线示例。
只需将 xml 保存在可绘制文件夹中: 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>

使用 LinearLayout 和背景来显示线条。

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

我希望这有帮助。

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.

怪我鬧 2024-09-07 03:07:17

一个棘手的方法可能是这样的:

1)在你想要一行的地方添加一个视图。

2) 将 android:background 设置为可以设置颜色和不透明度的十六进制值。

例如:

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

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" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文