2013年12月31日星期二
2013年12月28日星期六
創建圓角的EditText
創建圓角的EditText:
首先創建/res/drawable/roundcorner.xml文件.
在佈局文件, 設置android:background="@drawable/roundcorner".
首先創建/res/drawable/roundcorner.xml文件.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5dp"
android:shape="rectangle" >
<solid android:color="#B0B0B0" />
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
</shape>
在佈局文件, 設置android:background="@drawable/roundcorner".
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_launcher"
android:gravity="left|bottom"
android:textColor="#F0F0F0"
android:background="@drawable/roundcorner"
android:hint="hello" >
</EditText>
</LinearLayout>
在EditText上添加圖標
在EditText上添加圖標的實例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10sp"
android:drawablePadding="5dp"
android:drawableStart="@drawable/ic_launcher"
android:gravity="left|bottom"
android:textColor="#F0F0F0"
android:background="#B0B0B0"
android:hint="hello" >
</EditText>
</LinearLayout>
2013年12月24日星期二
Google Maps Android API Utility Library (谷歌地圖AndroidAPI工具庫)
Google Maps Android API Utility Library (谷歌地圖AndroidAPI工具庫) 是一個開放源碼的類庫, 為地圖應用程序提供先進的功能. 這是提供源代碼的 GitHub 網站.
Maps Shortcuts: Android Maps Utility Library
Maps Shortcuts: Android Maps Utility Library
2013年12月18日星期三
2013年12月10日星期二
2013年12月8日星期日
實現 GestureDetector.OnGestureListener 檢測手勢
這個示例代碼通過實現 GestureDetector.OnGestureListener 檢測用戶的手勢操作:
相關帖子:
- 手勢檢測 GestureDetector.SimpleOnGestureListener
![]() |
| 實現 GestureDetector.OnGestureListener 檢測手勢 |
package com.example.androidgesturedetector;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.view.GestureDetectorCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.TextView;
public class MainActivity extends Activity {
String info;
TextView infoView;
private GestureDetectorCompat myGestureDetectorCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
infoView = new TextView(this);
setContentView(infoView);
info = "";
infoView.setText(info);
myGestureDetectorCompat = new GestureDetectorCompat(this,
myOnGestureListener);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
myGestureDetectorCompat.onTouchEvent(event);
return super.onTouchEvent(event);
}
GestureDetector.OnGestureListener myOnGestureListener = new
GestureDetector.OnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
info = "onDown - " + e.getX() + " : " + e.getY() + "\n";
infoView.setText(info);
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
info += "onFling - " + "\n" + " e1 - " + e1.getX() + " : "
+ e1.getY() + "\n" + " e2 - " + e2.getX() + " : "
+ e2.getY() + "\n" + " velocityX = " + velocityX + "\n"
+ " velocityY = " + velocityY + "\n";
infoView.setText(info);
return false;
}
@Override
public void onLongPress(MotionEvent e) {
info += "onLongPress - " + e.getX() + " : " + e.getY() + "\n";
infoView.setText(info);
}
@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
info += "onScroll\n";
infoView.setText(info);
return false;
}
@Override
public void onShowPress(MotionEvent e) {
info += "onShowPress - " + e.getX() + " : " + e.getY() + "\n";
infoView.setText(info);
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
info += "onSingleTapUp - " + e.getX() + " : " + e.getY() + "\n";
infoView.setText(info);
return false;
}
};
}
相關帖子:
- 手勢檢測 GestureDetector.SimpleOnGestureListener
2013年12月2日星期一
手勢檢測 GestureDetector.SimpleOnGestureListener
GestureDetector.SimpleOnGestureListener 類為檢測手勢(Gesture)提供一種簡單的方式. 它實現了 GestureDetector.OnGestureListener 和 GestureDetector.OnDoubleTapListener 的所有方法. 你只需要擴展 GestureDetector.SimpleOnGestureListener 子類,並重寫所需的方法便可以。
返回值: 如果該事件被消耗掉 return true,否則 return false.
示例代碼:
相關帖子:
- 實現 GestureDetector.OnGestureListener 檢測手勢
返回值: 如果該事件被消耗掉 return true,否則 return false.
示例代碼:
package com.example.androidsimpleongesturelistener;
import android.os.Bundle;
import android.support.v4.view.GestureDetectorCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.TextView;
import android.app.Activity;
public class MainActivity extends Activity {
private GestureDetectorCompat myGestureDetector;
String info;
TextView infoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
infoView = new TextView(this);
setContentView(infoView);
info = "";
infoView.setText(info);
myGestureDetector =
new GestureDetectorCompat(this, new MyGestureListener());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
this.myGestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDoubleTap(MotionEvent e) {
info += "onDoubleTap - " +
e.getX() + " : " + e.getY() +
"\n";
infoView.setText(info);
return super.onDoubleTap(e);
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
info += "onDoubleTapEvent - " +
e.getX() + " : " + e.getY() +
"\n";
infoView.setText(info);
return super.onDoubleTapEvent(e);
}
@Override
public boolean onDown(MotionEvent e) {
info = "onDown - " +
e.getX() + " : " + e.getY() +
"\n";
infoView.setText(info);
return super.onDown(e);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
info += "onFling - " + "\n" +
" e1 - " + e1.getX() + " : " + e1.getY() + "\n" +
" e2 - " + e2.getX() + " : " + e2.getY() + "\n" +
" velocityX = " + velocityX + "\n" +
" velocityY = " + velocityY + "\n";
infoView.setText(info);
return super.onFling(e1, e2, velocityX, velocityY);
}
@Override
public void onLongPress(MotionEvent e) {
info += "onLongPress - " +
e.getX() + " : " + e.getY() +
"\n";
infoView.setText(info);
super.onLongPress(e);
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
/*
info += "onScroll - " + "\n" +
" e1 - " + e1.getX() + " : " + e1.getY() + "\n" +
" e2 - " + e2.getX() + " : " + e2.getY() + "\n" +
" distanceX = " + distanceX + "\n" +
" distanceY = " + distanceY + "\n";
infoView.setText(info);
*/
info += "onScroll\n";
infoView.setText(info);
return super.onScroll(e1, e2, distanceX, distanceY);
}
@Override
public void onShowPress(MotionEvent e) {
info += "onShowPress - " +
e.getX() + " : " + e.getY() +
"\n";
infoView.setText(info);
super.onShowPress(e);
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
info += "onSingleTapConfirmed - " +
e.getX() + " : " + e.getY() +
"\n";
infoView.setText(info);
return super.onSingleTapConfirmed(e);
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
info += "onSingleTapUp - " +
e.getX() + " : " + e.getY() +
"\n";
infoView.setText(info);
return super.onSingleTapUp(e);
}
}
}
![]() |
| 手勢檢測 GestureDetector.SimpleOnGestureListener |
相關帖子:
- 實現 GestureDetector.OnGestureListener 檢測手勢
訂閱:
留言 (Atom)


