use*_*356 5 user-interface android bitmap android-layout android-bitmap
我想用渐变背景绘制图像.我已经创建了一个可绘制的位图资源,如下所示
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bg"
android:tileMode="repeat"
android:gravity="bottom"
/>
Run Code Online (Sandbox Code Playgroud)
如您所知,定义tileMode时会忽略重力.我尝试创建自己的类,它继承自BitmapDrawable,但我无法取得成功.请帮我应用这两个属性:tileMode和gravity.
我没有清楚地理解这个问题。这里的目标是什么?
是否使用带有tileMode的渐变图像(如.png .jpg)?
或者它使用透明图标并使其背景渐变?
另外,为什么在使用tileMode时需要重力?tileMode 表示用相同的图像平铺位图的整个区域。因为它会对整个图像执行此操作,所以没有必要对该图像施加重力,因为所有图像都会被填充。
如果目标是在屏幕的某些部分使用此可绘制位图,请将其添加到您的布局中:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/mydrawablebitmap"
android:id="@+id/imageview1" />
Run Code Online (Sandbox Code Playgroud)
您可以将其放入您的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>
Run Code Online (Sandbox Code Playgroud)
然后将此图像视图添加到您的布局中:
<ImageView
android:id="@+id/myimagewithgradientbackground"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@drawable/gradient"
android:src="@drawable/foregroundimage" />
Run Code Online (Sandbox Code Playgroud)
如果您向我提供有关该问题的更多详细信息,我将继续相应地编辑我的答案。
| 归档时间: |
|
| 查看次数: |
378 次 |
| 最近记录: |