2013-07-01 38 views
0

我想在运行时用颜色设置表面视图边框。我做这样的,但它不工作没有设置颜色的表面视图边框

//Video View to play the vidoes ads. 
surfaceView = new SurfaceView(context); 
GradientDrawable drawable = new GradientDrawable(); 
drawable.setShape(GradientDrawable.RECTANGLE); 
drawable.setStroke(5, Color.MAGENTA); 
surfaceView.setBackgroundDrawable(drawable); 
surfaceView.setPadding(10, 10, 10, 10); 

当我设置这个视频随后停止显示。

请帮我让它正常工作。

在此先感谢

+0

可以动态地设置的背景颜色,并给予余量图像 –

+1

赞image.setPadding(2,2,2,2); image.setBackgroundColor(Color.WHITE); –

+0

@YogeshTatwal如何设置颜色名称“绿色”的颜色。如果我收到蓝色,那么它应该设置为蓝色 –

回答

0

您可以创建边框形式的XML样式,然后设置为ImageView的或任何其他视图。

<shape 
    android:padding="10dp" 
    android:shape="rectangle" > 

    <solid android:color="give hexa code of your color" /> 

    <stroke 
     android:width="2dp" /> 

    <corners 
     android:bottomLeftRadius="10dp" 
     android:bottomRightRadius="10dp" 
     android:topLeftRadius="10dp" 
     android:topRightRadius="10dp" /> 

</shape> 

将此文件保存为可绘制文件夹中的绘图。例如rectangle.xml

imageView1.setBackgroundDrawable(R.drawable.rectangle); 
+0

hoe动态设置颜色.. –