Android开发随笔

来源:互联网 发布:js替换所有换行符 编辑:程序博客网 时间:2024/05/21 06:23

TextView 里面有一个属性drawable属性可以在文字四个方位加图片


异常: Circular dependencies cannot exist in RelativeLayout

解决:布局空间的id重命名


在图片上写文字可以用FrameLayout,帧布局就是从左上角,一层一层叠上去的


popupwindow:

LayoutInflater inflater = getLayoutInflater();View layout = inflater.inflate(R.layout.helppopupwindow, null);helpPopup = new PopupWindow(layout, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//设置泡泡外部可点helpPopup.setOutsideTouchable(true);helpPopup.setFocusable(true);//有些人说不设置点击事件不能dimiss,不过经试验不设置点击事件,这个点击外部区域和Back也能dimisshelpPopup.setTouchInterceptor(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {return false;    //如果返回时true,该事件不会被调用}});//为泡泡设置一个背景,一个可以点击的区域,否则不能dismisshelpPopup.setBackgroundDrawable(new BitmapDrawable());helpPopup.showAsDropDown(findViewById(R.id.help), 30, 0);

打电话:

Intent contactslos = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+"0755-28890800"));                                //Intent.ACTION_CALL打电话的权限,Uri.parse是相关的路径,就是拨打路径->电话号码                                                                startActivity(contactslos);

还要在Android的Manifest.xml中设置打电话相关的权限


圆形进度条设置:

1.第一种方法,用图片作为圆形进度条,使用动画效果旋转

xml:

    <ProgressBar     android:id="@+id/progressBar1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"     android:indeterminate="false"     android:indeterminateDrawable="@drawable/progressbar_circle"    />

res/drawable/progressbar_circle

<?xml version="1.0" encoding="utf-8"?><rotate  xmlns:android="http://schemas.android.com/apk/res/android"    android:fromDegrees="0"    android:toDegrees="360"    android:pivotX="50%"    android:pivotY="50%"    android:drawable="@drawable/progressbar" />  

progressbar是显示的图片


2.第二种方法,用颜色实现

xml:

<ProgressBar     android:id="@+id/progressBar2"    android:layout_width="wrap_content"    android:layout_height="wrap_content"     android:indeterminate="false"     android:indeterminateDrawable="@drawable/progressbar_circle_color"    />

res/drawable/progressbar_circle_color

<?xml version="1.0" encoding="utf-8"?><rotate  xmlns:android="http://schemas.android.com/apk/res/android"    android:fromDegrees="0"    android:toDegrees="360"    android:pivotX="50%"    android:pivotY="50%" >        <shape       android:innerRadiusRatio="3"    //内圆半径比:内圆的半径是圆环的宽度除以3,可以被innerRadius覆盖,默认是9,值越大内半径越小       android:shape="ring"    //形状环形       android:thicknessRatio="8"    //圆环厚度比:圆环的厚度是圆环的宽度除以8,可以被thickness覆盖,默认是3,值越大圆环越细       android:useLevel="false" >    //useLevel值为true则使用一系列的图片循环显示Level_list,为false则显示渐变色        <gradient          android:centerColor="#FFDC35"    //渐变中间颜色          android:centerY="0.50"    //渐变色中心Y位置          android:endColor="#000000"    //结束颜色          android:startColor="#FFFFFF"    //开始颜色          android:type="sweep"    //类型:linear线性渐变、radial放射性渐变,以开始色为中心、sweep扫描线性渐变(具体怎么渐变自己去试验一下)          android:useLevel="false" />    </shape>    </rotate>

一个环形的颜色渐变
3.第三种方法,使用动画效果

xml:

    <ProgressBar     android:id="@+id/progressBar3"    android:layout_width="wrap_content"    android:layout_height="wrap_content"     android:indeterminate="false"     android:indeterminateDrawable="@anim/progressbar_circle_anim"    />

res/anim/progressbar_circle_anim

<?xml version="1.0" encoding="UTF-8"?>  <animation-list android:oneshot="false"  xmlns:android="http://schemas.android.com/apk/res/android">    <item android:duration="100" android:drawable="@drawable/brithdayicon1" />    <item android:duration="100" android:drawable="@drawable/brithdayicon2" />    <item android:duration="100" android:drawable="@drawable/brithdayicon3" />    <item android:duration="100" android:drawable="@drawable/brithdayicon4" />    <item android:duration="100" android:drawable="@drawable/brithdayicon5" />    <item android:duration="100" android:drawable="@drawable/brithdayicon6" /></animation-list>   

通过动画的一帧帧的循环显示,可以弄出圆形的效果

4.第四中通过样式显示圆形进度条

xml:

<ProgressBar  style="@style/myCircleProgressBar"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:indeterminateDuration="500" />
res/drawable/progressbar_circle

<rotate  xmlns:android="http://schemas.android.com/apk/res/android"    android:fromDegrees="0"    android:toDegrees="360"    android:pivotX="50%"    android:pivotY="50%"    android:drawable="@drawable/progressbar" />

res/valus/styles

<style name="myCircleProgressBar" >  <item name="android:indeterminateDrawable">@drawable/progressbar_circle</item>  <item name="android:minWidth">50dip</item>   //内圆  <item name="android:maxWidth">50dip</item>    //外圆  <item name="android:minHeight">50dip</item>  <item name="android:maxHeight">50dip</item></style>

第四种和第一种差不多,只不过显示的方式有一点差异


第五种圆形进度条显示(用图片和动画效果)

xml:

<ImageView         android:id="@+id/img"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:src="@drawable/progressbar"/>
MainActivity:

Animation anim = AnimationUtils.loadAnimation(getBaseContext(), R.anim.progressbar);    //加载自定义动画anim.setDuration(1000);  //每个动画的持续时间image.startAnimation(anim);anim.setInterpolator(new Interpolator() {private final int frameCount = 12;   //分拆成12部分@Overridepublic float getInterpolation(float input) {// TODO Auto-generated method stubreturn (float)Math.floor(input*frameCount)/frameCount;   //每部分的速率...0.1,.0.2...对应着图片的相对位置}});
res/anim/progressbar

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <rotate         android:fromDegrees="0"        android:toDegrees="360"        android:pivotX="50%"        android:pivotY="50%"        android:repeatCount="infinite"/>   //属性无限旋转下去</set>

第六种显示方法

xml:

    <com.huaqiang.dialogtest.ProgressView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/progressbar">

绑定相对的class


ProgressView:

package com.huaqiang.dialogtest;import com.huaqiang.dialogteststyle.R;import android.content.Context;import android.content.res.TypedArray;import android.util.AttributeSet;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.view.animation.Interpolator;import android.widget.ImageView;public class ProgressView extends ImageView {    public ProgressView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);        setAnimation(attrs);    }    public ProgressView(Context context, AttributeSet attrs) {        super(context, attrs);        setAnimation(attrs);    }    public ProgressView(Context context) {        super(context);    }//获取attrs里面设置的参数    private void setAnimation(AttributeSet attrs) {        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ProgressView);        int frameCount = a.getInt(R.styleable.ProgressView_frameCount, 12);  //获取attrs里面设置的属性值,没有就赋予12        int duration = a.getInt(R.styleable.ProgressView_duration, 1000);        a.recycle();    //保持以后使用该属性的一致性        setAnimation(frameCount, duration);    }//设置动画效果    public void setAnimation(final int frameCount, final int duration) {        Animation a = AnimationUtils.loadAnimation(getContext(), R.anim.progressbar);        a.setDuration(duration);        a.setInterpolator(new Interpolator() {@Overridepublic float getInterpolation(float input) {// TODO Auto-generated method stubreturn (float) (Math.floor(input*frameCount)/frameCount);}});        startAnimation(a);    }}

res\values\attrs

<?xml version="1.0" encoding="utf-8"?><resources>        <declare-styleable name="ProgressView">        <attr name="frameCount" format="integer"/>        <attr name="duration" format="integer" />    </declare-styleable></resources>

关于这些属性,还有待研究

关于Animation中的Rotate效果的旋转中心点问题:

有时候设置相对于控件本身或者相对于父控件的旋转中心点用50%或者0.5f的相对值达不到预期的效果,具体什么原因不知道,有可能是单位转换问题,这时候可以

采取使用绝对单位,这样就可以实现预期的效果。


0 0
原创粉丝点击