【问题标题】:Drawing tiled bitmap with bottom alignment绘制具有底部对齐的平铺位图
【发布时间】:2012-10-09 13:29:55
【问题描述】:

我想绘制一个带有渐变背景的图像。我创建了一个可绘制的位图资源,如下所示

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/bg"
        android:tileMode="repeat"
        android:gravity="bottom"
        />

如您所知,定义 tileMode 时会忽略重力。我尝试创建自己的类,该类继承自 BitmapDrawable,但我无法成功。 请帮我应用这两个属性:tileMode 和重力。

【问题讨论】:

    标签: android android-layout user-interface bitmap android-bitmap


    【解决方案1】:

    我没有清楚地理解这个问题。这里的目标是什么?

    是否使用带有 tileMode 的渐变图像(如 .png .jpg)?

    还是使用透明图标并使其成为背景渐变?

    还有,为什么在使用 tileMode 时需要重力? tileMode 表示用相同的图像平铺位图的整个区域。由于它会对整个图像执行此操作,因此不会对该图像施加重力,因为所有图像都会被填充。

    如果目标是在屏幕的某些部分使用此可绘制位图,请将其添加到您的布局中:

    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/mydrawablebitmap"
    android:id="@+id/imageview1" />
    

    你可以把它放到你的 layout.xml 中,并设置你自己的宽度和高度,然后对齐任何你喜欢的。

    如果目标是使用图像并将其作为背景,那么您就是这样做的:

    在你的drawable文件夹中创建一个gradient.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient
        android:startColor="#E0E0E0"
        android:endColor="#FFFFFF"
        android:angle="-90"/>
    </shape>
    

    然后将此图像视图添加到您的布局中:

    <ImageView
        android:id="@+id/myimagewithgradientbackground"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:background="@drawable/gradient"
        android:src="@drawable/foregroundimage" />
    

    如果您提供有关该问题的更多详细信息,我将继续并相应地编辑我的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-01
      • 2016-05-02
      相关资源
      最近更新 更多