本篇文章给大家谈谈织梦用PHP判断flag自定义属性是否存在,然后调用自定义属性,以及phpstudy安装织梦的知识点,同时本文还将给你拓展Android自定义View之自定义属性、android自定
本篇文章给大家谈谈织梦用PHP判断flag自定义属性是否存在,然后调用自定义属性,以及phpstudy安装织梦的知识点,同时本文还将给你拓展Android 自定义View之自定义属性、android 自定义控件 自定义属性详细介绍、Android 自定义控件之自定义属性、Android自定义控件——自定义属性等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- 织梦用PHP判断flag自定义属性是否存在,然后调用自定义属性(phpstudy安装织梦)
- Android 自定义View之自定义属性
- android 自定义控件 自定义属性详细介绍
- Android 自定义控件之自定义属性
- Android自定义控件——自定义属性
织梦用PHP判断flag自定义属性是否存在,然后调用自定义属性(phpstudy安装织梦)
{dede:arclist typeid='1' flag='c'}
<li><a href=http://www.dede58.com/a/dedejq/"[field:arcurl/]">[field:title/]</a></li>
{/dede:arclist}
如果在新闻内容详细页把自定义属性调用出来用,试试用
{dede:field.flag/}
显示出来的是不是文字,而是
c,p
这是正常的,因为他只是调用数据表里的内容,如果要把指定的文字调用出来就需要array处理一下,用到PHP的strstr函数,下面给出办法
{dede:field name='array' runphp='yes'}
if(@me['typeid']=='1' && strstr(@me['flag'],'c')=='c') @me='[推荐]'.@me['title']';
else @me=@me['title'];
{/dede:field}
注意这个例子增加了栏目的ID判断条件,如果不需要判断就直接用
{dede:field name='array' runphp='yes'}
if(strstr(@me['flag'],'c')=='c') @me='[推荐]'.@me['title'];
else @me=@me['title'];
{/dede:field}
php判断字符串是否包含办法
办法一、使用strstr,strstr返回需要判断是否被包含的字符开始到结束的字符串,如果没有返回值,则不包含。
举例,判断是否包含字符“#”:
<?php
$str='abc#defg';
$in=strstr($str,'#');
echo $in;//输出结果为:#defg
?>
办法二、使用stristr,它的用法和strstr的完全一样。**的区别是stristr不区分大小写,而strstr区分大小写。可以根据实际情况是否区分大小写来使用。
办法三、使用strpos,但它对中文件的支持不是很好,它的返回值为boolean型,也就是true和false(真和假)。执行速度比stristr和strstr都快,strpos函数中有一个参数用于指定判断的位置,默认为空,即判断整个字符串。
下面看例子:
<?php
$str='bde';
$in='b';
$output=strpos($str,$in);
?>
办法四、将字符串用explode来拆分数组再判断。如下:
function chstr($str,$in){ $tmparr = explode($in,$str); if(count($tmparr)>1){ return true; }else{ return false; } } $str='abc#defg'; $in='#';//判断是否包含#这个字符 $bh=chstr($str,$in); if($bn){ echo '字符串'.$str.'包含'.$in; }else{ echo '字符串'.$str.'不包含'.$in; }本文章网址:http://www.ppssdd.com/code/11317.html。转载请保留出处,谢谢合作!
Android 自定义View之自定义属性
Android 自定义View之自定义属性
一:前言
1.什么是命名空间呢
android的命名空间和自定义命名空间
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:前缀
android:名称,可以自定义
url:代表的就是空间,是个没有用的url,是统一资源标识符,相对于一个常量
2.配置文件attrs.xml
在res下的values文件加下创建一个attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomNumAnimView">
<attr name="round_radius" format="dimension" />
<attr name="round_color" format="color" />
<attr name="text_color" format="color" />
<attr name="text_size" format="dimension" />
</declare-styleable>
</resources>
//格式解析
declare-styleable
name:属性集合名称
attr
name:属性名称
format:格式
共有11种格式
1.reference(资源id)
<ImageView android:background = "@drawable/图片ID"/>
2.color
<TextView android:textColor = "#00FF00" />
3.boolean
4.dimension(尺寸)(dp)
5.float(浮点值)
6.integer(整形值)
7.string(字符串)
8.fraction(百分比)
9.enum(枚举值)
<declare-styleable name="名称">
<attr name="orientation">
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
</attr>
</declare-styleable>
10.flag(位或运算)
注意:位运算类型的属性在使用的过程中可以使用多个值
11.混合属性(使用|分开多个属性)
3.获取属性值
public CustomNumAnimView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//获取自定义属性
TypedArray array=context.obtainStyledAttributes(attrs,R.styleable.CustomNumAnimView,defStyleAttr,0);
int roundColor=array.getColor(R.styleable.CustomNumAnimView_round_color, ContextCompat.getColor(context,R.color.purple_200));
float roundRadius=array.getDimension(R.styleable.CustomNumAnimView_round_radius,50);
int textColor=array.getColor(R.styleable.CustomNumAnimView_text_color, Color.WHITE);
float textSize=array.getDimension(R.styleable.CustomNumAnimView_text_size,30);
array.recycle();
}
二:自定义View使用自定义属性
public class CustomNumAnimView extends View {
private int roundColor; //圆的颜色
private int textColor; //数字的颜色
private float textSize; //数字字体大小
private float roundRadius; //圆的半径
private Paint mPaint; //画笔
private Rect textRect; //包裹数字的矩形
private boolean isFirstInit = false; //是否是第一次初始化
private CustomPoint leftPoint; //左边的数字的实时点
private String leftNum = "9";
private ValueAnimator leftAnim; //左边数字动画
private boolean isLeftNumInvalidate = false; //左边数字是否重绘界面
private CustomPoint middlePoint; //中间的数字的实时点
private String middleNum = "9";
private ValueAnimator middleAnim; //中间数字动画
private boolean isMiddleNumInvalidate = false; //中间数字是否重绘界面
private CustomPoint rightPoint; //右边的数字的实时点
private String rightNum = "9";
private ValueAnimator rightAnim; //右边数字动画
private boolean isRightNumInvalidate = false; //右边数字是否重绘界面
public CustomNumAnimView(Context context) {
this(context, null);
}
public CustomNumAnimView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomNumAnimView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//获取自定义属性
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CustomNumAnimView, defStyleAttr, 0);
roundColor = array.getColor(R.styleable.CustomNumAnimView_round_color, ContextCompat.getColor(context, R.color.purple_200));
roundRadius = array.getDimension(R.styleable.CustomNumAnimView_round_radius, 50);
textColor = array.getColor(R.styleable.CustomNumAnimView_text_color, Color.WHITE);
textSize = array.getDimension(R.styleable.CustomNumAnimView_text_size, 30);
array.recycle();
//创建画笔
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);//抗锯齿标志
mPaint.setTextSize(textSize);//画笔设置文本大小
textRect = new Rect();
//得到数字矩形的宽高,以用来画数字的时候纠正数字的位置
mPaint.getTextBounds(middleNum, 0, middleNum.length(), textRect);
}
/**
* 测量
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int size;
int mode;
int width;
int height;
size = MeasureSpec.getSize(widthMeasureSpec);
mode = MeasureSpec.getMode(widthMeasureSpec);
if (mode == MeasureSpec.EXACTLY) { //确定的值或者MATCH_PARENT
width = size;
} else { //表示WARP_CONTENT
width = (int) (2 * roundRadius);
}
mode = MeasureSpec.getMode(heightMeasureSpec);
size = MeasureSpec.getSize(heightMeasureSpec);
if (mode == MeasureSpec.EXACTLY) { //确定的值或者MATCH_PARENT
height = size;
} else { //表示WARP_CONTENT
height = (int) (2 * roundRadius);
}
setMeasuredDimension(width, height);
}
/**
* 重写onDraw方法
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!isFirstInit) {
//是
//初始化三串数字
leftPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2 - roundRadius / 2, (float) (getMeasuredHeight() / 2 - roundRadius * (Math.sqrt(3) / 2) - textRect.height() / 2));
middlePoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2, getMeasuredHeight() / 2 - roundRadius - textRect.height() / 2);
rightPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2 + roundRadius / 2, (float) (getMeasuredHeight() / 2 - roundRadius * (Math.sqrt(3) / 2) - textRect.height() / 2));
drawText(canvas);
startAnimation(); //开始动画
isFirstInit = true;
} else {
drawText(canvas);
}
}
private boolean isAnimStart(ValueAnimator anim) {
return !anim.isStarted();
}
public void startAnim() {
if (isAnimStart(leftAnim)) {
leftAnim.start();
}
if (isAnimStart(middleAnim)) {
middleAnim.start();
}
if (isAnimStart(rightAnim)) {
rightAnim.start();
}
}
/**
* 在onDestroy方法中调用
*/
public void stopAnim() {
leftAnim.end();
middleAnim.end();
rightAnim.end();
leftAnim = null;
middleAnim = null;
rightAnim = null;
}
/**
* 画数字
*/
private void drawText(Canvas canvas) {
//画圆
mPaint.setAntiAlias(true);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setColor(roundColor);
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, roundRadius, mPaint);
//写数字
mPaint.setColor(textColor);
mPaint.setTextSize(textSize);
if (isLeftNumInvalidate) {
canvas.drawText(leftNum, leftPoint.getX(), leftPoint.getY(), mPaint);
isLeftNumInvalidate = false;
}
if (isMiddleNumInvalidate) {
canvas.drawText(middleNum, middlePoint.getX(), middlePoint.getY(), mPaint);
isMiddleNumInvalidate = false;
}
if (isRightNumInvalidate) {
canvas.drawText(rightNum, rightPoint.getX(), rightPoint.getY(), mPaint);
isRightNumInvalidate = false;
}
}
/**
* 开始动画
*/
private void startAnimation() {
startLeft();
startMiddle();
startRight();
}
private void startRight() {
final CustomPoint startPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2 + roundRadius / 2, (float) (getMeasuredHeight() / 2 - roundRadius * (Math.sqrt(3) / 2) - textRect.height() / 2));
final CustomPoint endPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2 + roundRadius / 2, (float) (getMeasuredHeight() / 2 + roundRadius * (Math.sqrt(3) / 2) + textRect.height() / 2));
rightAnim = ValueAnimator.ofObject(new CustomPointEvaluator(), startPoint, endPoint);
rightAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
rightPoint = (CustomPoint) animation.getAnimatedValue();
isRightNumInvalidate = true;
invalidate();
}
});
rightAnim.addListener(new CustomAnimListener() {
@Override
public void onAnimationRepeat(Animator animation) {
rightNum = getRandom();
}
});
rightAnim.setStartDelay(150);
rightAnim.setDuration(300);
rightAnim.setRepeatCount(ValueAnimator.INFINITE);
}
private void startMiddle() {
//初始化中间数字的开始点的位置
final CustomPoint startPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2, getMeasuredHeight() / 2 - roundRadius - textRect.height() / 2);
//初始化中间数字的结束点的位置
final CustomPoint endPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2, getMeasuredHeight() / 2 + roundRadius + textRect.height() / 2);
middleAnim = ValueAnimator.ofObject(new CustomPointEvaluator(), startPoint, endPoint);
//监听从起始点到终点过程中点的变化,并获取点然后重新绘制界面
middleAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
middlePoint = (CustomPoint) animation.getAnimatedValue();
isMiddleNumInvalidate = true;
invalidate();
}
});
middleAnim.addListener(new CustomAnimListener() {
@Override
public void onAnimationRepeat(Animator animation) {
middleNum = getRandom();
}
});
middleAnim.setDuration(300);
middleAnim.setRepeatCount(ValueAnimator.INFINITE);
}
private void startLeft() {
//属性动画
final CustomPoint startPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2 - roundRadius / 2, (float) (getMeasuredHeight() / 2 - roundRadius * (Math.sqrt(3) / 2) - textRect.height() / 2));
final CustomPoint endPoint = new CustomPoint(getMeasuredWidth() / 2 - textRect.width() / 2 - roundRadius / 2, (float) (getMeasuredHeight() / 2 + roundRadius * (Math.sqrt(3) / 2) + textRect.height() / 2));
leftAnim = ValueAnimator.ofObject(new CustomPointEvaluator(), startPoint, endPoint);
leftAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
leftPoint = (CustomPoint) animation.getAnimatedValue();
isLeftNumInvalidate = true;
invalidate();
}
});
leftAnim.addListener(new CustomAnimListener() {
@Override
public void onAnimationRepeat(Animator animation) {
middleNum = getRandom();
}
});
leftAnim.setStartDelay(100);
leftAnim.setDuration(300);
leftAnim.setRepeatCount(ValueAnimator.INFINITE);
}
/**
* 获取0-9之间的随机数
*
* @return
*/
private String getRandom() {
int random = (int) (Math.random() * 9);
return String.valueOf(random);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:lsp="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.ruan.mygitignore.CustomNumAnimView
android:id="@+id/custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
lsp:round_radius="50dp"
lsp:text_size="16dp"/>
</LinearLayout>
这是一个自定view的使用的自定义属性
结尾:每一个小小的进步,都是日后的财富
android 自定义控件 自定义属性详细介绍
自定义控件在android中无处不见,自定义控件给了我们很大的方便。比如说,一个视图为imageview ,imagebutton,textview 等诸多控件的组合,用的地方有很多,我们不可能每次都来写3个的组合,既浪费时间,效率又低。在这种情况下,我们就可以自定义一个view来替换他们,不仅提升了效率并且在xml中运用也是相当的美观。一、控件自定义属性介绍
以下示例中代码均在values/attrs.xml 中定义,属性均可随意命名。
1. reference:参考某一资源ID。
示例:
[java]
<declare-styleable name = "名称">
<attr name = "background" format = "reference" />
<attr name = "src" format = "reference" />
</declare-styleable>
2. color:颜色值。
示例:
[java]
<declare-styleable name = "名称">
<attr name = "textColor" format = "color" />
</declare-styleable>