导航:首页 > 操作系统 > android滚动渐变

android滚动渐变

发布时间:2022-06-17 21:48:12

‘壹’ 怎么在android上面做出根据形状来渐变的效果

<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"] 其中rectagle矩形,oval椭圆,line水平直线,ring环形
<shape>中子节点的常用属性:
<gradient> 渐变
Android:startColor 起始颜色
Android:endColor 结束颜色
Android:angle 渐变角度,0从左到右,90表示从下到上,数值为45的整数倍,默认为0;
Android:type 渐变的样式 liner线性渐变 radial环形渐变 sweep <solid > 填充
Android:color 填充的颜色
<stroke >描边
Android:width 描边的宽度
Android:color 描边的颜色
Android:dashWidth 表示'-'横线的宽度
Android:dashGap 表示'-'横线之间的距离
<corners >圆角
Android:radius 圆角的半径 值越大角越圆
Android:topRightRadius 右上圆角半径
Android:bottomLeftRadius 右下圆角角半径
Android:topLeftRadius 左上圆角半径
Android:bottomRightRadius 左下圆角半径
<padding >填充
android:bottom="1.0dip" 底部填充
android:left="1.0dip" 左边填充
android:right="1.0dip" 右边填充
android:top="0.0dip" 上面填充
Selector
根据不同的选定状态来定义不同的现实效果 分为四大属性:
android:state_selected 是选中
android:state_focused 是获得焦点
android:state_pressed 是点击
android:state_enabled 是设置是否响应事件,指所有事件
android:state_window_focused 默认时的背景图片 引用位置:res/drawable/文件的名称.xml
使用的方法:
java代码中:R.drawable.文件的名称 XML中:Android:background="@drawable/文件的名称"
示例:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片-->
<item Android:drawable="@drawable/pic1" />
<!-- 没有焦点时的背景图片 -->
<item
Android:state_window_focused="false"
android:drawable="@drawable/pic_blue"
/>
<!-- 非触摸模式下获得焦点并单击时的背景图片 -->
<item
Android:state_focused="true"
android:state_pressed="true"
android:drawable= "@drawable/pic_red"
/>
<!-- 触摸模式下单击时的背景图片-->
<item
Android:state_focused="false"
Android:state_pressed="true"
Android:drawable="@drawable/pic_pink"
/>
<!--选中时的图片背景-->
<item
Android:state_selected="true"
android:drawable="@drawable/pic_orange"
/>
<!--获得焦点时的图片背景-->
<item
Android:state_focused="true"
Android:drawable="@drawable/pic_green"
/>
</selector>

layer-list(多个shape)
将多个图片或上面两种效果按照顺序层叠起来
示例:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/android_red"
android:gravity="center" />
</item>
<item android:top="10dp" android:left="10dp">
<bitmap android:src="@drawable/android_green"
android:gravity="center" />
</item>
<item android:top="20dp" android:left="20dp">
<bitmap android:src="@drawable/android_blue"
android:gravity="center" />
</item>
</layer-list>

感觉很像多个drawable
三者可以结合使用
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor_press" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor" />
</shape>
</item>
</layer-list>
</item>
</selector>

‘贰’ 如何通过android实现alpha渐变动画效果

Android动画分为四种:alpha(渐变透明度),scale(渐变尺寸伸缩),translate(画面转换位置移动),rotate(画面转移旋转);今天先写第一个动画alpha。
动画效果有两种实现:
一、在xml中定义:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 透明度控制动画效果 alpha
浮点型值:
fromAlpha 属性为动画起始时透明度
toAlpha 属性为动画结束时透明度
说明:
0.0表示完全透明
1.0表示完全不透明
以上值取0.0-1.0之间的float数据类型的数字

长整型值:
ration 属性为动画持续时间
说明:
时间以毫秒为单位
-->

<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:ration="5000"
/>

</set>
二、在页面Activity中声明:
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);

完成动画渐变透明度的参数设定后,我们就要开始在应用中使用它:
public class SplashActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);

View view = View.inflate(SplashActivity.this, R.layout.welcome, null);
setContentView(view);
//动画效果参数直接定义
Animation animation = new AlphaAnimation(0.1f, 1.0f);
animation.setDuration(5000);

//动画效果从XMl文件中定义
// Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
view.setAnimation(animation);
}
}
这样我们就完成了预定的动画效果,但是我们的最终目的是动画效果完毕以后跳转到相应的页面,所以我们对动画添加了监听:
animation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
}
});
这样的话,我们在动画的持续时间中预加载我们的资源,当动画结束以后跳转到我们的主页面;
详细步骤和完整源码可以参考:http://www.cnblogs.com/sishuiliuyun/p/3167581.html

‘叁’ 在android中怎么至上而下渐变

这个是输出一层颜色渐变的效果,而你的是多层的,做法一样,弄几个小的的三角形同样的画法画到上面。而颜色的值是不可能是线性的值,你只能自己定义每层三角形的颜色,这个是你要做的。 这个我直接用NDK自带的HELLO-GL2给你弄的,就设置下三角形

‘肆’ android 怎么在轮播时实现多种动画效果,如第一张到第二张渐变,第二张到第三张旋转

Android系统自带的一个多页面管理控件,它可以实现子界面的自动切换:

首先 需要为ViewFlipper加入View

(1) 静态导入:在layout布局文件中直接导入

(2) 动态导入:addView()方法

ViewPlipper常用方法:

setInAnimation:设置View进入屏幕时候使用的动画

setOutAnimation:设置View退出屏幕时候使用的动画

showNext:调用该函数来显示ViewFlipper里面的下一个View

showPrevious:调用该函数来显示ViewFlipper里面的上一个View

setFlipInterval:设置View之间切换的时间间隔

startFlipping使用上面设置的时间间隔来开始切换所有的View,切换会循环进行

stopFlipping:停止View切换

讲了这么多,那么我们今天要实现的是什么呢?

(1) 利用ViewFlipper实现图片的轮播

(2) 支持手势滑动的ViewFlipper

我们需要先准备几张图片:把图片放进drawable中

创建两个动画:在res下面新建一个folder里面新建两个xml:

‘伍’ android属性动画怎么渐变

3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三种动画模式在SDK中被称为property animation,view animation,drawable animation。?
1. View Animation(Tween Animation)
View Animation(Tween Animation):补间动画,给出两个关键帧,通过一些算法将给定属性值在给定的时间内在两个关键帧间渐变。
View animation只能应用于View对象,而且只支持一部分属性,如支持缩放旋转而不支持背景颜色的改变。
而且对于View animation,它只是改变了View对象绘制的位置,而没有改变View对象本身,比如,你有一个Button,坐标 (100,100),Width:200,Height:50,而你有一个动画使其变为Width:100,Height:100,你会发现动画过程中触 发按钮点击的区域仍是(100,100)-(300,150)。
View Animation就是一系列View形状的变换,如大小的缩放,透明度的改变,位置的改变,动画的定义既可以用代码定义也可以用XML定义,当然,建议用XML定义。
可以给一个View同时设置多个动画,比如从透明至不透明的淡入效果,与从小到大的放大效果,这些动画可以同时进行,也可以在一个完成之后开始另一个。
用XML定义的动画放在/res/anim/文件夹内,XML文件的根元素可以 为<alpha>,<scale>,<translate>,<rotate>,interpolator 元素或<set>(表示以上几个动画的集合,set可以嵌套)。默认情况下,所有动画是同时进行的,可以通过startOffset属性设置 各个动画的开始偏移(开始时间)来达到动画顺序播放的效果。
可以通过设置interpolator属性改变动画渐变的方式,如AccelerateInterpolator,开始时慢,然后逐渐加快。默认为。

‘陆’ android 循环滑动渐变的效果怎么做

<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"] 其中rectagle矩形,oval椭圆,line水平直线,ring环形
<shape>中子节点的常用属性:
<gradient> 渐变
Android:startColor 起始颜色
Android:endColor 结束颜色
Android:angle 渐变角度,0从左到右,90表示从下到上,数值为45的整数倍,默认为0;
Android:type 渐变的样式 liner线性渐变 radial环形渐变 sweep <solid > 填充
Android:color 填充的颜色
<stroke >描边
Android:width 描边的宽度
Android:color 描边的颜色
Android:dashWidth 表示'-'横线的宽度
Android:dashGap 表示'-'横线之间的距离
<corners >圆角
Android:radius 圆角的半径 值越大角越圆
Android:topRightRadius 右上圆角半径
Android:bottomLeftRadius 右下圆角角半径
Android:topLeftRadius 左上圆角半径
Android:bottomRightRadius 左下圆角半径
<padding >填充
android:bottom="1.0dip" 底部填充
android:left="1.0dip" 左边填充
android:right="1.0dip" 右边填充
android:top="0.0dip" 上面填充
Selector
根据不同的选定状态来定义不同的现实效果 分为四大属性:
android:state_selected 是选中
android:state_focused 是获得焦点
android:state_pressed 是点击
android:state_enabled 是设置是否响应事件,指所有事件
android:state_window_focused 默认时的背景图片 引用位置:res/drawable/文件的名称.xml
使用的方法:
Java代码中:R.drawable.文件的名称 XML中:Android:background="@drawable/文件的名称"
示例:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片-->
<item Android:drawable="@drawable/pic1" />
<!-- 没有焦点时的背景图片 -->
<item
Android:state_window_focused="false"
android:drawable="@drawable/pic_blue"
/>
<!-- 非触摸模式下获得焦点并单击时的背景图片 -->
<item
Android:state_focused="true"
android:state_pressed="true"
android:drawable= "@drawable/pic_red"
/>
<!-- 触摸模式下单击时的背景图片-->
<item
Android:state_focused="false"
Android:state_pressed="true"
Android:drawable="@drawable/pic_pink"
/>
<!--选中时的图片背景-->
<item
Android:state_selected="true"
android:drawable="@drawable/pic_orange"
/>
<!--获得焦点时的图片背景-->
<item
Android:state_focused="true"
Android:drawable="@drawable/pic_green"
/>
</selector>

layer-list(多个shape)
将多个图片或上面两种效果按照顺序层叠起来
示例:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/android_red"
android:gravity="center" />
</item>
<item android:top="10dp" android:left="10dp">
<bitmap android:src="@drawable/android_green"
android:gravity="center" />
</item>
<item android:top="20dp" android:left="20dp">
<bitmap android:src="@drawable/android_blue"
android:gravity="center" />
</item>
</layer-list>

感觉很像多个drawable
三者可以结合使用
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor_press" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="#ffaaaaaa" />

<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />

<solid android:color="@color/setting_item_bgcolor" />
</shape>
</item>
</layer-list>
</item>
</selector>

‘柒’ android控件背景颜色动态随机渐变

这个你只能使用shape来完成。因为是点击后随机变,不能使用xml写死的那种,你得用java代码来生成和配置GradientDrawable,设置不同的color.如果不会用,可以参照:

‘捌’ android渐变设置占比

比较简单的一种方式实现颜色渐变,我们通过定制一个对应的shape文件,配置其属性之后,直接作为android:background赋值给对应的View即可。
1.创建XML文件
在你的drawable文件夹下创建shape资源:
shape_gradient.xml文件代码如下:
android:endColor="@color/colorPrimary"
android:startColor="@color/colorAccent" />
解释一下各个层级的标签:
[shape] 根标签,声明一个shape
[gradient] 声明该shape的属性-渐变色,除此外还有其他属性如corners、stroke、size等等
[android:angle]渐变色的角度,举例来说,0代表从上至下颜色渐变;45代表从左至右颜色渐变;90代表从下至上颜色渐变…
[android:startColor&android:endColor] 很好理解,渐变开始的颜色和渐变结束时的颜色(从什么颜色变到什么颜色)
2.将渐变色赋予对应的View
直接放入MainActivity的layout文件中

‘玖’ android颜色渐变如何实现从四周往中心渐变 或者从中心往四周渐变 都行,不是 从左往右

android 颜色渐变是指通知xml或者java代码,设置相关参数,是界面的某个指定的视图显示成从开始位置的颜色,逐渐过度到结尾位置的颜色的技术。

android颜色渐变的分类有:

LinearGradient线性渐变

RadialGradient镜像渐变

SweepGradient角度渐变


一、LinearGradient线性渐变
顾名思义,是只颜色在一个直线方向上逐渐改变。

文件代码:

<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<gradient
android:endColor="#0000FF"
android:startColor="#FF0000"
android:type="linear"/>

</shape>

效果:

阅读全文

与android滚动渐变相关的资料

热点内容
2016android版本下载 浏览:40
程序员开车卖服装 浏览:393
快速记忆法pdf 浏览:516
java定义异常类 浏览:707
的运行命令 浏览:585
24v电动驻车空调压缩机 浏览:842
老程序员编程步骤 浏览:305
物理去除加密软件 浏览:227
汇编语言可调试编译器 浏览:447
jpeg如何转成pdf 浏览:841
微机室为什么有服务器 浏览:657
安卓手机怎么打语音电话不断网 浏览:458
单片机汇编头文件 浏览:946
juniper命令行 浏览:68
程序员咨询销售工作怎么样 浏览:782
苹果文件服务器是什么 浏览:180
企业透明加密软件有监视功能吗 浏览:494
桌面的运行命令 浏览:10
主流厂商服务器维护流程是什么 浏览:807
压缩棉的被子先洗洗在用 浏览:242