【问题标题】:Background image and scaled foreground image in ImageViewImageView 中的背景图像和缩放的前景图像
【发布时间】:2013-09-18 11:46:21
【问题描述】:

我们有一个带有背景图像的图像视图,我们想要放置 文本视图上方的 ImageView 作为前景“图像”居中 相对于 ImageView 的大小。

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

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

如果使用填充,则不同的屏幕尺寸可能会出现问题。

前景图像应缩放到 ImageView 大小的高度和宽度的 50%,并且 textview 应放置在前景图像下方。

黑色外方块:imageview边界,黑色圆圈:背景图片,读取方块:前景图片,蓝色矩形:前景文字

【问题讨论】:

    标签: android textview imageview image-scaling image-size


    【解决方案1】:

    这很重,但使用这种布局,应该可以工作:

    <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>
    

    希望对你有帮助

    【讨论】:

      最近更新 更多