【问题标题】:How to create background for LinearLayout as shown in the image below如何为 LinearLayout 创建背景,如下图所示
【发布时间】:2015-02-27 13:02:30
【问题描述】:

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

【问题讨论】:

  • 最简单的方法是放一张图片,比如背景。
  • 指定你投-ive投票的原因......
  • 我想以某种实用的方式绘制它,不想使用图片......@MikiFranko
  • 如果是这样,你必须使用画布,你可以随心所欲地画。
  • @MikiFranko 上面的图像在顶部边缘也有阴影,所以我如何在画布上绘制它。有什么帮助??????

标签: android


【解决方案1】:

创建一个黄色背景的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>

【讨论】:

    【解决方案2】:

    您可以使用相对布局将视图添加到另一个视图之上。对于上面提到的图像,您只需要两个图像并且您必须像这样创建布局:

    <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();
    

    【讨论】:

    • 但是根据我的要求,我必须以某种方式在不使用图像的情况下以编程方式绘制它......
    • @user3074539 扩展View 并覆盖方法onDraw()。你可以在那里画任何你喜欢的东西(以编程方式)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    相关资源
    最近更新 更多