我刚刚使用android形状创建了一个红色圆圈:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="4"
android:shape="ring"
android:thicknessRatio="9"
android:useLevel="false" >
<solid android:color="#FF0000" />
<size
android:height="48dip"
android:width="48dip" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这真的很酷,但我无法将圆圈的背景颜色设置为我的颜色.我尝试过,android:background="#FFFFFF"但在我的布局中看起来总是黑色.如何设置上述形状的背景?
我想将Relative或LinearLayout的背景设置为自定义drawable.我希望形状在底部绘制两条水平线,使中心部分透明(空).
下面绘制垂直居中的水平线,我需要它们与形状的底部对齐.(如果将矩形添加为项目,则可以看到形状扩展为父级的尺寸,但线条仍然居中对齐).
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="line">
<stroke android:width="1dip" android:color="#99b8b9bd" />
<size android:height="1dip" />
</shape>
</item>
<item>
<shape android:shape="line" android:top="1dip">
<stroke android:width="1dip" android:color="#FFFFFFFF" />
<size android:height="1dip" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) 我需要为xml drawable中的颜色设置不透明度值.但是当我尝试添加两个不透明度值(#20C0C0C0)时,不起作用.颜色看起来完全透明.
这是我的代码......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
android:radius="2dp" />
<solid
android:color="#CDCDCD" />
<stroke
android:width="2dp"
android:color="@android:color/darker_gray" />
<size
android:height="60dp"
android:width="80dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
有人有想法吗?谢谢你的帮助.
我有一个关于.shape函数的简单问题,这让我很困惑.
a = np.array([1, 2, 3]) # Create a rank 1 array
print(type(a)) # Prints "<class 'numpy.ndarray'>"
print(a.shape) # Prints "(3,)"
b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 array
print(b.shape) # Prints "(2, 3)"
Run Code Online (Sandbox Code Playgroud)
.shape究竟做了什么?计算多少行,多少列,然后a.shape假设为,(1,3),一行三列,对吧?
我可以创建一个矩形的形状,所有边都是圆形的.但是,我想要的是一个矩形形状,只有2个边缘是圆形的.这可能吗?
我基本上将ListView看起来像一个带有圆边的气泡.我想添加一个标题,其顶部的两个边缘是圆形的,页脚的两个底边是圆形的.
我有一个Drawable xml文件(background.xml):
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
...........
</shape>
</item>
<item android:id="@+id/shape_id">
<shape android:shape="rectangle">
<solid android:color="#ffefefef" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
由LinearLayout使用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/background"
android:id="@+id/layout_id"
>
Run Code Online (Sandbox Code Playgroud)
现在我需要shape_id根据某些条件在运行时更改形状纯色.这该怎么做?
我尝试创建半圆背景,在development IDE preview它工作,但当我在模拟器中启动它不起作用.
这是我的形状代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:height="50dp">
<shape>
<solid android:color="@color/colorAccentDark" />
</shape>
</item>
<item android:top="-500dp" android:bottom="0dp" android:left="-100dp" android:right="-100dp">
<shape>
<corners android:radius="500dp" />
<solid android:color="@color/colorAccentDark" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_profile"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_avatar"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_default_avatar"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"/>
<TextView
android:id="@+id/profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/profile_avatar"
android:layout_marginTop="20dp"
android:textColor="@color/neutralWhite"
android:textStyle="bold"
android:textSize="18sp"
android:text="Avatar Ang"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4.04">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Android!"/>
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
也许还有其他任何调整来处理它?谢谢
我想要实现的是在其中使用具有几层的Drawable,但在运行时控制一些值,例如渐变的startColor.这是我在my_layered_shape.xml中的内容:
<?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:width="1dp" android:color="#FF000000" />
<solid android:color="#FFFFFFFF" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#FF000000" />
<gradient
android:startColor="#FFFFFFFF"
android:centerColor="#FFFFFF88"
android:endColor="#FFFFFFFF"
android:gradientRadius="250"
android:centerX="1"
android:centerY="0"
android:angle="315"
/>
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
如果我使用mMyImageView.setBackgroundResource(R.drawable.my_layered_shape),它的工作原理.我不介意拆分xml,如果必须的话,或者以编程方式完成整个事情,只要有办法获得各种颜色值.我将以编程方式进行的概念(即我在代码中执行与此xml相同的最佳操作)是:
Drawable[] layers = new Drawable[2];
ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
sd1.getPaint().setColor(0xFFFFFFFF);
sd1.getPaint().setStyle(Style.STROKE);
sd1.getPaint().setStrokeWidth(1);
// sd1.getPaint().somehow_set_stroke_color?
ShapeDrawable sd2 = new ShapeDrawable(new RectShape());
sd2.getPaint().setColor(0xFF000000);
sd2.getPaint().setStyle(Style.STROKE);
// sd2.getPaint().somehow_set_stroke_color?
// sd2.getPaint().somehow_set_gradient_params?
layers[0] = sd1;
layers[1] = sd2;
LayerDrawable composite = new LayerDrawable(layers); …Run Code Online (Sandbox Code Playgroud) 我想使用离散颜色绘制具有六组以上数据的不同形状的线条.问题是1)为线条颜色和形状生成了不同的图例,但应该只有一个带有线条颜色和形状的图例,2)在修正线条颜色图例的标题时,颜色会消失.
t=seq(0,360,20)
for (ip in seq(0,10)) {
if (ip==0) {
df<-data.frame(t=t,y=sin(t*pi/180)+ip/2,sn=ip+100)
} else {
tdf<-data.frame(t=t,y=sin(t*pi/180)+ip/2,sn=ip+100)
df<-rbind(df,tdf)
}
}
head(df)
# No plot
# Error: A continuous variable can not be mapped to shape
gp <- ggplot(df,aes(x=t,y=y,group=sn,color=sn,shape=sn))
gp <- gp + labs(title = "Demo more than 6 shapes", x="Theat (deg)", y="Magnitude")
gp <- gp + geom_line() + geom_point()
print(gp)
# No plot
# Error: A continuous variable can not be mapped to shape (doesn't like integers)
gp <- ggplot(df,aes(x=t,y=y,group=sn,color=sn,shape=as.integer(sn)))
gp <- …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个简单的Drawable,我想将其设置为视图的背景(使用setBackgroundDrawable).我只想将drawable的背景划分为2个相等的矩形(50% - 50%),第一个想要用黑色填充,第二个用白色填充:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/back_color_1">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<item android:id="@+id/back_color_2">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
如何在可绘制XML定义文件中指定每个形状的宽度应为50%?像android:width ="50%"之类的东西.
(我正在使用Android 3.0,但我认为这是一个普通的Android问题.)
PS:您可以在CSS或XAML中执行此操作.