2014-12-31 36 views
-9

如何为LinearLayout创建背景,如下图所示。我不知道该怎么做。如何为LinearLayout创建背景,如下图所示

enter image description here

+1

最简单的方法是把一个图片的大小如背景。 –

+1

指定你给出-ive投票的理由.... –

+0

我想以某种方式绘制它,不想使用图片.... @MikiFranko –

回答

0

可以使用相对布局上方添加另一个查看查看。对于上面提到的图像,你只需要两张图片而且你要这样创建布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/white_image" /> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/yellow_image" /> 

</RelativeLayout> 

添加动态视图,您可以覆盖位图:

LayoutInflater inflater = LayoutInflater.from(getActivity()); 
     Bitmap bitmapCopy1 = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888); 
     canvas1 = new Canvas(bitmapCopy1); 
     Bitmap pinImage = Utility.createBitmap(pinFloor); 
     canvas1.drawBitmap(pinImage, leftPos[i], topPos[i], new Paint());  
     firstImage.setImageBitmap(firstBitmap); 
     firstImage.setImageBitmap(bitmapCopy1); 
     firstImage.invalidate(); 
+0

但根据我的要求,我必须以编程方式绘制它,而不使用图像...... –

+0

@ user3074539扩展'View'并覆盖方法'onDraw()'。你可以绘制任何你喜欢的东西(编程)。 – skywall

0

与背景创建RelativeLayout的黄色,并在顶部添加圆形图像。

这是一个更为动态的解决方案要比使用单一形象为RelativeLayout将根据屏幕大小/方向改变大小,而不是影响圈

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffc20e"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/circle_image" /> 

</RelativeLayout> 
相关问题