你好,朋友们,我想改变颜色的渐变像下面的图片。我试了这么多天,但没有运气。你能帮帮我吗?提前感谢!

我可以用渐变LinearLayout绘制颜色,但是我想在运行时更改这个颜色。
发布于 2013-11-20 10:43:16
这可以通过一帧一帧的animation.In来实现,您的活动可以在下面编写代码:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_layout);
ImageView animation animation = (ImageView)findViewById(R.id.imageAnimation);
animation.setBackgroundResource(R.drawable.anim_fbyf);
}
@Override
public void onWindowFocusChanged (boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
AnimationDrawable frameAnimation =
(AnimationDrawable) animation.getBackground();
if(hasFocus)
frameAnimation.start();
else
frameAnimation.stop();
}在名为anim_fbyf.xml的可绘图文件夹中创建1 xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/frame0" android:duration="350" />
<item android:drawable="@drawable/frame1" android:duration="350" />
<item android:drawable="@drawable/frame2" android:duration="350" />
<item android:drawable="@drawable/frame3" android:duration="350" />
<item android:drawable="@drawable/frame4" android:duration="350" />
<item android:drawable="@drawable/frame5" android:duration="350" />
<item android:drawable="@drawable/frame6" android:duration="350" />
<item android:drawable="@drawable/frame7" android:duration="350" />
<item android:drawable="@drawable/frame8" android:duration="350" />
<item android:drawable="@drawable/frame9" android:duration="350" />
<item android:drawable="@drawable/frame10" android:duration="350" />
<item android:drawable="@drawable/frame11" android:duration="350" />
<item android:drawable="@drawable/frame12" android:duration="350" />
<item android:drawable="@drawable/frame13" android:duration="350" />
</animation-list>您可以根据需要设置持续时间和不添加任何帧。
我增加了13帧(或gif图像),并将持续时间设置为350毫秒。
输出:
下面是有13帧的图像

发布于 2013-11-19 08:10:26
你可以试试这个:
int h = v.getHeight();
ShapeDrawable mDrawable = new ShapeDrawable(new RectShape());
mDrawable.getPaint().setShader(new LinearGradient(0, 0, 0, h, Color.parseColor("#330000FF"), Color.parseColor("#110000FF"), Shader.TileMode.REPEAT));
v.setBackgroundDrawable(mDrawable);关于getView()重载函数(ListAdapter)
https://stackoverflow.com/questions/20064647
复制相似问题