首页 文章

ImageView中的背景图像和缩放的前景图像

提问于
浏览
1

我们有一个带有背景图像的imageview,我们希望将ImageView放在textview上方,作为相对于ImageView大小居中的前景“图像” .

selectedImageView = (ImageView) view.findViewById(R.id.selectedImage);
        selectedImageView.setBackgroundResource(R.drawable.back_item);
        selectedImageView.setImageResource(R.drawable.icon_alarm);

上面的代码使前景图像拉伸到ImageView的大小,但我们希望前景是“内部”背景圆 .

如果使用填充,则可能存在不同屏幕尺寸的问题 .

前景图像应缩放到ImageView大小的高度和宽度的50%,文本视图应放在前景图像下方 .

Black outer square: the imageview boundary, black circle: background image, read square: foreground image, blue rectangle: foreground text

黑色外部正方形:图像视图边界,黑色圆圈:背景图像,读取正方形:前景图像,蓝色矩形:前景文本

1 回答

  • 0

    这很重,但使用这种布局应该有效:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ImageView
            android:id="@+id/background"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
    
            android:src="@drawable/ic_action_search" />
    
        <ImageView
            android:id="@+id/foreground"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/ic_launcher" />
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageView1"
            android:layout_centerHorizontal="true"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    

    希望它会有所帮助

相关问题