当前位置: 编程技术>移动开发
本页文章导读:
▪拖动旋钮到处跑 拖动按钮到处跑
1. 布局文件view plaincopy to clipboardprint?<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_pare.........
▪ 设立ScrollView滚动条的颜色 设置ScrollView滚动条的颜色
很多开发者在做Android UI时不知道如何设置ScrollView滚动条控件的滑块颜色,其实通过ScrollView的xml布局属性android:scrollbarThumbVertical可以关联一个drawable对象,比如说.........
▪ 加载远道图片到 View 加载远程图片到 View
NSURL *url=[NSURL URLWithString:@"http://..../Icons/icon.ico"];NSData *data=[NSData dataWithContentsOfURL:url];UIImage *tmpimage=[[UIImage alloc] initWithData:data];
UIImageView *imageview =[[UIImageView alloc] initWithFrame.........
[1]拖动旋钮到处跑
来源: 互联网 发布时间: 2014-02-18
拖动按钮到处跑
1. 布局文件
view plaincopy to clipboardprint?
<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/btn_hello"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><Button android:id="@+id/btn_hello" android:layout_width="fill_parent"android:layout_height="wrap_content" android:text="@string/hello" /></LinearLayout>2. 代码
view plaincopy to clipboardprint?
package com.roiding.sample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
public
class Touch extends Activity {
/** Called when the activity is first created. */
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button btn = (Button) findViewById(R.id.btn_hello);
btn.setOnTouchListener(new OnTouchListener() {
int[] temp = new
int[] { 0, 0 };
public
boolean onTouch(View v, MotionEvent event) {
int eventaction = event.getAction();
Log.i("&&&", "onTouchEvent:" + eventaction);
int x = (int) event.getRawX();
int y = (int) event.getRawY();
switch (eventaction) {
case MotionEvent.ACTION_DOWN: // touch down so check if the
temp[0] = (int) event.getX();
temp[1] = y - v.getTop();
break;
case MotionEvent.ACTION_MOVE: // touch drag with the ball
v.layout(x - temp[0], y - temp[1], x + v.getWidth()
- temp[0], y - temp[1] + v.getHeight());
v.postInvalidate();
break;
case MotionEvent.ACTION_UP:
break;
}
return
false;
}
});
}
}
1. 布局文件
view plaincopy to clipboardprint?
<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/btn_hello"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><Button android:id="@+id/btn_hello" android:layout_width="fill_parent"android:layout_height="wrap_content" android:text="@string/hello" /></LinearLayout>2. 代码
view plaincopy to clipboardprint?
package com.roiding.sample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
public
class Touch extends Activity {
/** Called when the activity is first created. */
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button btn = (Button) findViewById(R.id.btn_hello);
btn.setOnTouchListener(new OnTouchListener() {
int[] temp = new
int[] { 0, 0 };
public
boolean onTouch(View v, MotionEvent event) {
int eventaction = event.getAction();
Log.i("&&&", "onTouchEvent:" + eventaction);
int x = (int) event.getRawX();
int y = (int) event.getRawY();
switch (eventaction) {
case MotionEvent.ACTION_DOWN: // touch down so check if the
temp[0] = (int) event.getX();
temp[1] = y - v.getTop();
break;
case MotionEvent.ACTION_MOVE: // touch drag with the ball
v.layout(x - temp[0], y - temp[1], x + v.getWidth()
- temp[0], y - temp[1] + v.getHeight());
v.postInvalidate();
break;
case MotionEvent.ACTION_UP:
break;
}
return
false;
}
});
}
}
[2] 设立ScrollView滚动条的颜色
来源: 互联网 发布时间: 2014-02-18
设置ScrollView滚动条的颜色
很多开发者在做Android UI时不知道如何设置ScrollView滚动条控件的滑块颜色,其实通过ScrollView的xml布局属性android:scrollbarThumbVertical可以关联一个drawable对象,比如说在ScrollView中我们有
android:scrollbars="vertical" //滚动条是垂直的
android:scrollbarThumbVertical="@drawable/red" //垂直滚动条颜色为red,red可以是一个png的图片或用shape组成的xml图形文件组成的drawable对象。
很多开发者在做Android UI时不知道如何设置ScrollView滚动条控件的滑块颜色,其实通过ScrollView的xml布局属性android:scrollbarThumbVertical可以关联一个drawable对象,比如说在ScrollView中我们有
android:scrollbars="vertical" //滚动条是垂直的
android:scrollbarThumbVertical="@drawable/red" //垂直滚动条颜色为red,red可以是一个png的图片或用shape组成的xml图形文件组成的drawable对象。
[3] 加载远道图片到 View
来源: 互联网 发布时间: 2014-02-18
加载远程图片到 View
NSURL *url=[NSURL URLWithString:@"http://..../Icons/icon.ico"];
NSData *data=[NSData dataWithContentsOfURL:url];
UIImage *tmpimage=[[UIImage alloc] initWithData:data];
UIImageView *imageview =[[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageview.image=tmpimage;
[self.view addSubview:imageview];
最新技术文章: