当前位置: 编程技术>移动开发
本页文章导读:
▪给自个儿的应用程序添加系统偏好设置二 给自己的应用程序添加系统偏好设置二
Root.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
&l.........
▪ 一个简略的界面拖动切换效果类ScrollViewGroup 一个简单的界面拖动切换效果类ScrollViewGroup
网上找的一个简单的界面平滑切换类,我只改动了一点点代码。该类不能循环切换!
import android.content.Context;
import android.util.AttributeSet;
import andr.........
▪ 过程ID 进程ID
获取ID
Runtime r = Runtime.getRuntime();
java.lang.Process p = r.exec("ps");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inline;
while ((inlin.........
[1]给自个儿的应用程序添加系统偏好设置二
来源: 互联网 发布时间: 2014-02-18
给自己的应用程序添加系统偏好设置二
Root.plist
Other.plist
Root.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>StringsTable</key> <string>Root</string> <key>PreferenceSpecifiers</key> <array> <dict> <key>Type</key> <string>PSGroupSpecifier</string> <key>Title</key> <string>Group</string> </dict> <dict> <key>Type</key> <string>PSTextFieldSpecifier</string> <key>Title</key> <string>Name</string> <key>Key</key> <string>name_preference</string> <key>DefaultValue</key> <string></string> <key>IsSecure</key> <false/> <key>KeyboardType</key> <string>Alphabet</string> <key>AutocapitalizationType</key> <string>None</string> <key>AutocorrectionType</key> <string>No</string> </dict> <dict> <key>Type</key> <string>PSToggleSwitchSpecifier</string> <key>Title</key> <string>Enabled</string> <key>Key</key> <string>enabled_preference</string> <key>DefaultValue</key> <true/> </dict> <dict> <key>Type</key> <string>PSSliderSpecifier</string> <key>Key</key> <string>slider_preference</string> <key>DefaultValue</key> <real>0.5</real> <key>MinimumValue</key> <integer>0</integer> <key>MaximumValue</key> <integer>1</integer> <key>MinimumValueImage</key> <string></string> <key>MaximumValueImage</key> <string></string> </dict> <dict> <key>Type</key> <string>PSGroupSpecifier</string> <key>Title</key> <string>Group</string> </dict> <dict> <key>Type</key> <string>PSSliderSpecifier</string> <key>Key</key> <string>slider_preference</string> <key>DefaultValue</key> <real>0.5</real> <key>MinimumValue</key> <integer>0</integer> <key>MaximumValue</key> <integer>1</integer> <key>MinimumValueImage</key> <string></string> <key>MaximumValueImage</key> <string></string> </dict> <dict> <key>Titles</key> <array> <string>Option 1</string> <string>Option 2</string> </array> <key>Values</key> <array> <string>option 1</string> <string>option 2</string> </array> <key>Type</key> <string>PSMultiValueSpecifier</string> <key>Title</key> <string>Options</string> <key>Key</key> <string>enabled_preference</string> <key>DefaultValue</key> <true/> </dict> <dict> <key>Type</key> <string>PSGroupSpecifier</string> <key>Title</key> <string>Group</string> </dict> <dict> <key>File</key> <string>Other</string> <key>Title</key> <string>Other</string> <key>Type</key> <string>PSChildPaneSpecifier</string> </dict> </array> </dict> </plist>
Other.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>StringsTable</key> <string>Other</string> <key>PreferenceSpecifiers</key> <array> <dict> <key>FooterText</key> <string>FooterText</string> <key>Title</key> <string>Title</string> <key>Type</key> <string>PSGroupSpecifier</string> </dict> </array> </dict> </plist>
[2] 一个简略的界面拖动切换效果类ScrollViewGroup
来源: 互联网 发布时间: 2014-02-18
一个简单的界面拖动切换效果类ScrollViewGroup
网上找的一个简单的界面平滑切换类,我只改动了一点点代码。
该类不能循环切换!
三个切换小点:
用法:
布局:
网上找的一个简单的界面平滑切换类,我只改动了一点点代码。
该类不能循环切换!
import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.widget.Scroller; public class ScrollViewGroup extends ViewGroup { private static final String TAG = "scroller"; private Scroller scroller; private int currentScreenIndex; public int getCurrentScreenIndex() { return currentScreenIndex; } public void setCurrentScreenIndex(int currentScreenIndex) { this.currentScreenIndex = currentScreenIndex; } private GestureDetector gestureDetector; // 设置一个标志位,防止底层的onTouch事件重复处理UP事件 private boolean fling; public ScrollViewGroup(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initView(context); } public ScrollViewGroup(Context context, AttributeSet attrs) { super(context, attrs); initView(context); } public ScrollViewGroup(Context context) { super(context); initView(context); } private void initView(final Context context) { this.scroller = new Scroller(context); this.gestureDetector = new GestureDetector(new OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if ((distanceX > 0 && currentScreenIndex < getChildCount() - 1)// 防止移动过最后一页 || (distanceX < 0 && getScrollX() > 0)) {// 防止向第一页之前移动 scrollBy((int) distanceX, 0); } return true; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { Log.d(TAG, "min velocity >>>" + ViewConfiguration.get(context).getScaledMinimumFlingVelocity() + " current velocity>>" + velocityX); // 判断是否达到最小轻松速度,取绝对值的 if (Math.abs(velocityX) > ViewConfiguration.get(context).getScaledMinimumFlingVelocity()) { if (velocityX > 0 && currentScreenIndex > 0) {//手指从左往右划 Log.d(TAG, ">>>>fling to left"); fling = true; scrollToScreen(currentScreenIndex - 1); } else if (velocityX < 0 && currentScreenIndex < getChildCount() - 1) { Log.d(TAG, ">>>>fling to right"); fling = true; scrollToScreen(currentScreenIndex + 1); } } return true; } @Override public boolean onDown(MotionEvent e) { return false; } }); } @Override protected void onLayout(boolean changed, int left, int top, int right,int bottom) { Log.d(TAG, ">>left: " + left + " top: " + top + " right: " + right + " bottom:" + bottom); /** * 设置布局,将子视图顺序横屏排列 */ for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.setVisibility(View.VISIBLE); child.measure(right - left, bottom - top); child.layout(0 + i * getWidth(), 0, getWidth() + i * getWidth(), getHeight()); } //初始化显示第几个界面 int delta = currentScreenIndex * getWidth() - getScrollX(); scroller.startScroll(getScrollX(), 0, delta, 0, 0); invalidate(); } @Override public void computeScroll() { if (scroller.computeScrollOffset()) { scrollTo(scroller.getCurrX(), 0); postInvalidate(); } } @Override public boolean onTouchEvent(MotionEvent event) { gestureDetector.onTouchEvent(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: if (!fling) { snapToDestination(); } fling = false; break; default: break; } return true; } /** * 切换到指定屏 * * @param whichScreen */ private void scrollToScreen(int whichScreen) { if (getFocusedChild() != null && whichScreen != currentScreenIndex && getFocusedChild() == getChildAt(currentScreenIndex)) { getFocusedChild().clearFocus(); } final int delta = whichScreen * getWidth() - getScrollX(); scroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta) * 2); invalidate(); currentScreenIndex = whichScreen; if (onScreenChangeListener != null) { onScreenChangeListener.onScreenChange(currentScreenIndex); } } /** * 根据当前x坐标位置确定切换到第几屏 */ private void snapToDestination() { scrollToScreen((getScrollX() + (getWidth() / 2)) / getWidth()); } public interface OnScreenChangeListener { void onScreenChange(int currentIndex); } private OnScreenChangeListener onScreenChangeListener; public void setOnScreenChangeListener(OnScreenChangeListener onScreenChangeListener) { this.onScreenChangeListener = onScreenChangeListener; } }
三个切换小点:
import com.easymorse.scroll.ScrollViewGroup.OnScreenChangeListener; import android.content.Context; import android.util.AttributeSet; import android.widget.ImageView; import android.widget.LinearLayout; public class PageControlView extends LinearLayout { private Context context; private int count; public void bindScrollViewGroup(ScrollViewGroup scrollViewGroup) { this.count=scrollViewGroup.getChildCount(); generatePageControl(scrollViewGroup.getCurrentScreenIndex()); scrollViewGroup.setOnScreenChangeListener(new OnScreenChangeListener() { @Override public void onScreenChange(int currentIndex) { // TODO Auto-generated method stub generatePageControl(currentIndex); } }); } public PageControlView(Context context) { super(context); this.init(context); } public PageControlView(Context context, AttributeSet attrs) { super(context, attrs); this.init(context); } private void init(Context context) { this.context=context; } private void generatePageControl(int currentIndex) { this.removeAllViews(); for (int i = 0; i < this.count; i++) { ImageView imageView = new ImageView(context); if (currentIndex == i) { imageView.setImageResource(R.drawable.page_indicator_focused); } else { imageView.setImageResource(R.drawable.page_indicator); } this.addView(imageView); } } }
用法:
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; public class ScrollDemosActivity extends Activity { @SuppressWarnings("unused") private static final String TAG = "scroller"; private ScrollViewGroup viewGroup; private PageControlView pageControl; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); viewGroup = (ScrollViewGroup) findViewById(R.id.scrollViewGroup); ImageView imageView = new ImageView(this); imageView.setImageDrawable(getResources().getDrawable(R.drawable.a1)); viewGroup.addView(imageView); viewGroup.addView(View.inflate(this, R.layout.layout_0, null)); imageView = new ImageView(this); imageView.setImageDrawable(getResources().getDrawable(R.drawable.a2)); viewGroup.addView(imageView); viewGroup.setCurrentScreenIndex(2); pageControl=(PageControlView) findViewById(R.id.pageControl); pageControl.bindScrollViewGroup(viewGroup); } }
布局:
<?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" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" /> <RelativeLayout android:id="@+id/myView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" > <com.easymorse.scroll.ScrollViewGroup android:id="@+id/scrollViewGroup" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <com.easymorse.scroll.PageControlView android:id="@+id/pageControl" android:layout_width="fill_parent" android:layout_height="40px" android:background="#8f00000f" android:layout_alignParentBottom="true" android:gravity="center" /> </RelativeLayout> </LinearLayout> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
1 楼
mailyiran200101
2011-11-08
学习了,感谢
2 楼
114624915
2011-11-10
为什么动态布局只显示左上角啊
[3] 过程ID
来源: 互联网 发布时间: 2014-02-18
进程ID
获取ID
Runtime r = Runtime.getRuntime(); java.lang.Process p = r.exec("ps"); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String inline; while ((inline = br.readLine()) != null) { if (inline.endsWith(packageName)) { break; } } br.close(); StringTokenizer processInfoTokenizer = new StringTokenizer(inline); int count = 0; while (processInfoTokenizer.hasMoreTokens()) { count++; processId = processInfoTokenizer.nextToken(); if (count == 2) { break; } } r.exec("kill -15 " + processId);
最新技术文章: