public class CustomTitle extends Activity {
/**
* Initialization of the Activity after it is first created. Must at least
* call {@link android.app.Activity#setContentView(int)} to
* describe what is to be displayed in the screen.
* 显示在notification下面的一行
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
final TextView leftText = (TextView) findViewById(R.id.left_text);
final TextView rightText = (TextView) findViewById(R.id.right_text);
final EditText leftTextEdit = (EditText) findViewById(R.id.left_text_edit);
final EditText rightTextEdit = (EditText) findViewById(R.id.right_text_edit);
Button leftButton = (Button) findViewById(R.id.left_text_button);
Button rightButton = (Button) findViewById(R.id.right_text_button);
leftButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
leftText.setText(leftTextEdit.getText());
}
});
rightButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
rightText.setText(rightTextEdit.getText());
}
});
}
}
custom_title.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:baselineAligned="false"> <EditText android:id="@+id/left_text_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxEms="10" android:minEms="10" android:layout_gravity="center_vertical" android:text="@string/custom_title_left" /> <Button android:id="@+id/left_text_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/custom_title_left_button"/> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:baselineAligned="false"> <EditText android:id="@+id/right_text_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxEms="10" android:minEms="10" android:layout_gravity="center_vertical" android:text="@string/custom_title_right" /> <Button android:id="@+id/right_text_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/custom_title_right_button"/> </LinearLayout> </LinearLayout>
custom_title_1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/left_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="@string/custom_title_left" /> <TextView android:id="@+id/right_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="@string/custom_title_right" /> </RelativeLayout>
seekBar即可拖动的进度条,可以作为播放器的进度条来使用,使用起来相对简单一点,不过限制较多,需要的话必须重写
和播放器配合的话:
1、设置最大值
int mSecond = mediaPlayer.getDuration(); // 得到的是毫秒
seekBar.setMax(mSecond);
2、自动更新进度条:在Handler里不断给自己发delay消息
currentTime = mediaPlayer.getCurrentPosition();
seekBar.setProgress(currentTime);
handler.sendEmptyMessage(TIME_CHANGED, DELAY_TIME);
3、拉动进度条定位:为seedBar设置一个onSeekBarChangeListener
改写onProgressChanged
mediaPlayer.seekto(progress);
import android.graphics.Matrix;
import android.graphics.PointF;
import android.util.FloatMath;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
public class MulitPointTouchListener implements OnTouchListener {
Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;
PointF start = new PointF();
PointF mid = new PointF();
float oldDist = 1f;
@Override
public boolean onTouch(View v, MotionEvent event) {
ImageView view = (ImageView) v;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
matrix.set(view.getImageMatrix());
savedMatrix.set(matrix);
start.set(event.getX(), event.getY());
mode = DRAG;
break;
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = spacing(event);
if (oldDist > 10f) {
savedMatrix.set(matrix);
midPoint(mid, event);
mode = ZOOM;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
break;
case MotionEvent.ACTION_MOVE:
if (mode == DRAG) {
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x, event.getY()
- start.y);
} else if (mode == ZOOM) {
float newDist = spacing(event);
if (newDist > 10f) {
matrix.set(savedMatrix);
float scale = newDist / oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
break;
}
view.setImageMatrix(matrix);
return true;
}
private float spacing(MotionEvent event) {
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return FloatMath.sqrt(x * x + y * y);
}
private void midPoint(PointF point, MotionEvent event) {
float x = event.getX(0) + event.getX(1);
float y = event.getY(0) + event.getY(1);
point.set(x / 2, y / 2);
}
}
imageView.setOnTouchListener(new MulitPointTouchListener ());在xml中要将图片的缩放格式改成Matrix
注:android:scaleType="matrix"