好吧,我一直在阅读和搜索,现在我正在撞墙,试图解决这个问题.这是我到目前为止所拥有的:
package com.pockdroid.sandbox;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.widget.ImageView;
public class ShadowImageView extends ImageView {
private Rect mRect;
private Paint mPaint;
public ShadowImageView(Context context)
{
super(context);
mRect = new Rect();
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setShadowLayer(2f, 1f, 1f, Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas)
{
Rect r = mRect;
Paint paint = mPaint;
canvas.drawRect(r, paint);
super.onDraw(canvas);
}
@Override
protected void onMeasure(int w, int h)
{
super.onMeasure(w,h);
int mH, mW;
mW = getSuggestedMinimumWidth() < …Run Code Online (Sandbox Code Playgroud) 
考虑上面的图像. - 虚线划分了9-Patch png,我将从photoshop文件中切出.我需要它来创建一个弹出框. - 该盒子包含一个dropShadow,如本照片中的测量工具所示. - 粉色线条用于显示我将如何使用draw9Patch工具创建9-Patch.
我的问题是:如果我有一个带有9-Patch的View"Container"作为背景我需要确保它的子视图总是在白框内.我打算用这个填充.我打算将填充设置为与测量工具相等.因此,如果它在photoshop中为30px,我会layout_paddingLeft"=30dp"为容器设置.(设计是在MDPI,所以我假设这个转换是可以的).但是,不同密度的屏幕如何处理9路径.例如,测量面积是30px还是30dip?
我想在布局的右侧和底部添加一个光影.我尝试使用android:background="@android:drawable/dialog_holo_light_frame"但是它在布局的所有四个边上都添加了一个厚阴影.我需要创建哪些可绘制并设置为背景?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:drawable/dialog_holo_light_frame">
<ImageView
android:id="@+id/g"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_gravity="center"
android:src="@drawable/logo_icon"
android:visibility="visible"
android:clickable="true" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我目前正在使用包含ImageViews的GridView,并希望我的图像背后有阴影.例如,在网格中可能有15个图像随时可见.在假设我希望我的屏幕以50fps渲染以显得平滑的情况下工作,我的数学表明我希望每个ImageView的总绘制时间不会差于大约1.3ms.
我看了一下Romain Guy如何在他的Shelves应用程序中做阴影:http: //code.google.com/p/shelves/source/browse/trunk/Shelves/src/org/curiouscreature/android/shelves/util/ ImageUtilities.java
这似乎有道理,所以我创建了以下类:
public class ShadowImageView extends ImageView {
private static final int SHADOW_RADIUS = 8;
private static final int SHADOW_COLOR = 0x99000000;
private static final Paint SHADOW_PAINT = new Paint();
static {
SHADOW_PAINT.setShadowLayer(SHADOW_RADIUS / 2.0f, 0.0f,
0.0f, SHADOW_COLOR);
SHADOW_PAINT.setColor(0xFF000000);
SHADOW_PAINT.setStyle(Paint.Style.FILL);
}
public ShadowImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void onDraw(Canvas canvas) {
final int containerWidth = getMeasuredWidth();
final int containerHeight = getMeasuredHeight();
canvas.drawRect(
SHADOW_RADIUS / 2.0f,
SHADOW_RADIUS / 2.0f,
containerWidth …Run Code Online (Sandbox Code Playgroud) android android-ui android-listview android-imageview android-gridview