标签:android style blog http java color
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/pressed" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/focused" /> <item android:drawable="@drawable/normal" /> </selector>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button" android:text="按钮" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <level-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/lamp_off" android:minLevel="6" android:maxLevel="10" /> <item android:drawable="@drawable/lamp_on" android:minLevel="12" android:maxLevel="20" /> </level-list>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/imageview_lamp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/lamp_level" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick_LampOn" android:text="开灯" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick_LampOff" android:text="关灯" /> </LinearLayout>
package com.wwj.drawable; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ImageView; /** * 图像级别资源的使用 * * 在res/drawable建立图像级别资源 * * 然后在布局文件的控件中使用 * * @author wwj * */ public class LevelDrawableRes extends Activity { private ImageView ivLamp; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.level_res); ivLamp = (ImageView) findViewById(R.id.imageview_lamp); // 设置Level为8,显示lamp_off.png ivLamp.setImageLevel(8); } public void onClick_LampOn(View view) { // LevelListDrawable levelListDrawable = // (LevelListDrawable)ivLamp.getDrawable(); // levelListDrawable.setLevel(15); // 设置Level为15,显示lamp_on.png ivLamp.setImageLevel(15); } public void onClick_LampOff(View view) { // 设置Level为6,显示lamp_off.png ivLamp.getDrawable().setLevel(6); } }
<?xml version="1.0" encoding="utf-8"?> <transition xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/lamp_off" /> <item android:drawable="@drawable/lamp_on" /> </transition>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/imageview_lamp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/lamp_transition" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick_LampOn" android:text="开灯" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick_LampOff" android:text="关灯" /> </LinearLayout>
package com.wwj.drawable; import android.app.Activity; import android.graphics.drawable.TransitionDrawable; import android.os.Bundle; import android.view.View; import android.widget.ImageView; /** * 淡入淡出资源的使用 * * @author wwj * */ public class CrossFadeDrawableRes extends Activity { private ImageView ivLamp; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.cross_fade_res); ivLamp = (ImageView) findViewById(R.id.imageview_lamp); } public void onClick_LampOn(View view) { // 从第一个图像切换到第二个图像。其中使用1秒的时间完成淡入淡出效果 TransitionDrawable drawable = (TransitionDrawable) ivLamp.getDrawable(); drawable.startTransition(1000); } public void onClick_LampOff(View view) { // 从第二个图像切换第一个图像。其中使用1秒的时间完成淡入淡出效果 TransitionDrawable drawable = (TransitionDrawable) ivLamp.getDrawable(); drawable.reverseTransition(1000); } }
<?xml version="1.0" encoding="utf-8"?> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/logo" android:insetBottom="10dp" android:insetLeft="10dp" android:insetRight="10dp" android:insetTop="10dp" > </inset> <!-- android:insetBottom="10dp" 图像距离下边的距离 android:insetLeft="10dp" 图像距离左标的距离 android:insetRight="10dp" 图像距离右边的距离 android:insetTop="10dp" 图像距离上边的距离 -->
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/inset" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:clipOrientation="horizontal" android:drawable="@drawable/progress" android:gravity="left" />
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/background" android:orientation="vertical" > <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/clip" /> </LinearLayout>
package com.wwj.drawable; import android.app.Activity; import android.graphics.drawable.ClipDrawable; import android.os.Bundle; import android.widget.ImageView; /** * 剪切图像的使用 * * 在res/drawable目录下定义clip资源 * * @author wwj * */ public class ClipDrawableRes extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.clip_res); ImageView imageview = (ImageView) findViewById(R.id.image); ClipDrawable drawable = (ClipDrawable) imageview.getBackground(); // 截取30%的图像 drawable.setLevel(3000); } }
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/logo" android:scaleGravity="center_vertical|center_horizontal" android:scaleHeight="80%" android:scaleWidth="80%" > </scale>
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="45" android:endColor="#80FF00FF" android:startColor="#FFFF0000" /> <padding android:bottom="7dp" android:left="7dp" android:right="7dp" android:top="7dp" /> <stroke android:width="2dp" android:color="#FFF" /> <corners android:radius="8dp" /> </shape>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="20dp" android:background="@drawable/shape" android:text="Shape Label" /> </LinearLayout>
Android-自定义图像资源的使用(2),码迷,mamicode.com
标签:android style blog http java color
原文地址:http://blog.csdn.net/wwj_748/article/details/24698471