2013年10月25日 星期五

JQUERY Mobile cache問題

TableLayout

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0,1,2"
    >
<TableRow>
<Button
    android:id="@+id/Button1"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button1"
    />
<Button
    android:id="@+id/Button2"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button2"
    android:layout_span="2"
    />
</TableRow>
<TableRow>
<Button
    android:id="@+id/Button3"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button3"
    />
 <Button
    android:id="@+id/Button4"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button4"
    />
   <Button
    android:id="@+id/Button5"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button5"
    />
</TableRow>
</TableLayout>

2013年10月20日 星期日

popupwindow-彈出對話框

原文地址:http://code.eoe.cn/169
上方網址有demo檔案
/***
 * PopupWindow
 * 
 * @author zhangjia
 * 
 */
public class MainActivity extends Activity {
 private Button button;
 private PopupWindow popupWindow;
 private LinearLayout layout;
 private ListView listView;
 private String title[] = { "全部", "我的微博", "周边", "智能排版", "同学" };

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.main);
  button = (Button) findViewById(R.id.tv_title);
  button.setOnClickListener(new OnClickListener() {
   @Override
   public void onClick(View v) {
    button.getTop();
    int y = button.getBottom() * 3 / 2;
    int x = getWindowManager().getDefaultDisplay().getWidth() / 4;

    showPopupWindow(x, y);
   }
  });
 }

 public void showPopupWindow(int x, int y) {
  layout = (LinearLayout) LayoutInflater.from(MainActivity.this).inflate(
    R.layout.dialog, null);
  listView = (ListView) layout.findViewById(R.id.lv_dialog);
  listView.setAdapter(new ArrayAdapter<String>(MainActivity.this,
    R.layout.text, R.id.tv_text, title));

  popupWindow = new PopupWindow(MainActivity.this);
  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  popupWindow
    .setWidth(getWindowManager().getDefaultDisplay().getWidth() / 2);
  popupWindow.setHeight(300);
  popupWindow.setOutsideTouchable(true);
  popupWindow.setFocusable(true);
  popupWindow.setContentView(layout);
  // showAsDropDown会把里面的view作为参照物,所以要那满屏幕parent
  // popupWindow.showAsDropDown(findViewById(R.id.tv_title), x, 10);
  popupWindow.showAtLocation(findViewById(R.id.main), Gravity.LEFT
    | Gravity.TOP, x, y);//需要指定Gravity,默认情况是center.

  listView.setOnItemClickListener(new OnItemClickListener() {

   @Override
   public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
     long arg3) {
    button.setText(title[arg2]);
    popupWindow.dismiss();
    popupWindow = null;
   }
  });
 }

}

2013年10月19日 星期六

保持螢幕喚醒/恆亮狀態

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

2013年10月16日 星期三

FragmentTabHost + pageView實現可左右滑動的底部菜單

 1、用fragment + fragmentTabHost實現了底部菜單效果,其實原理和  TabActivity + tabhost是一樣的。                
 2、fragmentTabHost + ViewPage支付左右滑動切換Tab頁

原始檔下載:http://goo.gl/ppDvOa

android4.0 android:configChanges="orientation|keyboardHidden" 無效

改: android:configChanges="orientation|keyboardHidden|screenSize"

2013年10月15日 星期二

AndroidManifest.xml中 andorid 版本區別 versionCode, versionName

versionCode:給電腦看的,所以上google play更新apk時,這個代碼需要往上增加 ,Integer型態。

versionName:給使用者看的。

android用戶界面之ScrollView教程實例匯總

範例參考地方
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=172019

一、ScrollView教程
教你怎么样判断scrollview是否滑动到底部
http://www.eoeandroid.com/thread-154908-1-1.html

解决ScrollView嵌套GridView或者ListView冲突的问题
http://www.eoeandroid.com/thread-170392-1-1.html

ScrollView反弹效果的实现
http://www.eoeandroid.com/thread-100933-1-1.html

Android TextView和ScrollView
http://www.eoeandroid.com/thread-65415-1-1.html

Android中ScrollView - 滚动条控件
http://www.eoeandroid.com/thread-66884-1-1.html

Android 解决ListView 和 ScrollView 共存冲突的问题
http://www.eoeandroid.com/thread-56720-1-1.html

Android-ScrollView结合案例详解
http://www.eoeandroid.com/thread-159189-1-1.html

android ScrollView实现滚动显示
http://www.eoeandroid.com/thread-157937-1-1.html

自定义ScrollView,以解决viewflipper 与scrollview的手势冲突
http://www.eoeandroid.com/thread-118288-1-1.html

监听ScrollView滚动事件
http://www.eoeandroid.com/thread-92482-1-1.html

Android 解决ListView 和 ScrollView 共存冲突的问题
http://www.eoeandroid.com/thread-28997-1-1.html

scrollview禁用滚动实现方案
http://www.eoeandroid.com/thread-75434-1-1.html

[Android]固定螢幕不旋轉

Android 畫面保持縱向或橫向,

android:screenOrientation="portrait" 

portrait :縱向,
landscape:橫向)

2013年10月14日 星期一

webview相關語法設定

   開啟Javascript支持

  webview . getSettings (). setJavaScriptEnabled ( true );  
設置可以自動加載圖片
WebView . getSettings (). setLoadsImagesAutomatically ( true );

設置WevView要顯示的網頁

互聯網用:webView.loadUrl(" http://www.eoe.cn "); 本地文件用:webView.loadUrl(file:///android_asset/eoe.html);

處理返回鍵為返回上一頁

public  boolean  onKeyDown ( int  keyCode ,  KeyEvent  event )  { 
    LogUtil . i ( this ,  "keyCode="    keyCode ); 
    if  (( keyCode  ==  KeyEvent . KEYCODE_BACK )  &&  mWebView . canGoBack ())  { 
        mWebView . goBack (); 
        return  true ; 
    } 
    return  super . onKeyDown ( keyCode ,  event ); 
}

置android WebView 不顯示滾動條

android:scrollbars="none"

重寫shouldOverrideUrlLoading時指定url

指定只有url裡包含自己的網址的時候才在webview裡打開,否則還是啟動瀏覽器打開.
@Override 
public  boolean  shouldOverrideUrlLoading ( WebView  view ,  String  url )  { 
    LogUtil . i ( this ,  "url="    url ); 
    if  (  url . contains ( "eoe.cn" )  ==  true ){ 
        view . loadUrl ( url ); 
        return  true ; 
    } else { 
        Intent  in  =  new  Intent  ( Intent . ACTION_VIEW  ,  Uri . parse ( url )); 
        startActivity ( in ); 
        return  true ; 
    } 
}

android:scrollbarStyle控制滾動條位置

mWebView . setScrollBarStyle ( View . SCROLLBARS_INSIDE_OVERLAY );

2013年10月13日 星期日

Android ─ Textview 顯示html語法內容

mytextview.setText(Html.fromHtml("<h1>Hello,Word</h1>"));

Android TextView line-through 刪除線

TextView textview = (TextView) findViewById(R.id.textview1);
Paint paint = textview.getPaint();
paint.setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
paint.setAntiAlias(true);

2013年10月12日 星期六

Android - ActionBar

http://www.vogella.com/articles/AndroidActionBar/article.html

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_refresh"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:icon="@drawable/ic_action_search"
        android:title="Refresh"/>
    <item
        android:id="@+id/action_settings"
        android:title="Settings">
    </item>

</menu> 
@Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmenu, menu);
    return true;
  } 
@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menuitem1:
      Toast.makeText(this, "Menu Item 1 selected", Toast.LENGTH_SHORT)
          .show();
      break;
    case R.id.menuitem2:
      Toast.makeText(this, "Menu item 2 selected", Toast.LENGTH_SHORT)
          .show();
      break;

    default:
      break;
    }

    return true;
  } 

TextView顯示圖片

TextView ig = new TextView(this);

ig.setText("TextView");

Bitmap pic = BitmapFactory.decodeResource( getResources(), R.drawable.movie );
pic = Bitmap.createScaledBitmap( b, 128, 128, true );

ig.setCompoundDrawablesWithIntrinsicBounds( new BitmapDrawable(pic) // 左
                                          , null  // 上
                                          , getResources().getDrawable(R.drawable.pencil) // 右
                                          , null  // 下
                                          );

int dp = (int) (10 * getResources().getDisplayMetrics().density + 0.5f);
ig.setCompoundDrawablePadding(dp);

另一篇文章-Android TextView使用HTML处理字体样式、显示图片等
http://blog.csdn.net/dawanganban/article/details/11191265

2013年10月10日 星期四

android4.0系統菜單(Menu)添加Icon無效問題

      @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.main, menu);
setIconEnable(menu, true);
menu.add(0, MENU_ABOUT, 0, "關於").setIcon(android.R.drawable.ic_menu_info_details);
menu.add(0, MENU_Quit, 0, "離開").setIcon(android.R.drawable.ic_menu_close_clear_cancel);
return true;
}


private void setIconEnable(Menu menu, boolean enable)  
   {  
       try   
       {  
           Class<?> clazz = Class.forName("com.android.internal.view.menu.MenuBuilder");  
           Method m = clazz.getDeclaredMethod("setOptionalIconsVisible", boolean.class);  
           m.setAccessible(true);  
             
          
           m.invoke(menu, enable);  
             
       } catch (Exception e)   
       {  
           e.printStackTrace();  
       }  
   }  

2013年10月8日 星期二

Button OnClickListener

bt1.setOnClickListener(new Button.OnClickListener(){
           @Override
           public void onClick(View v) {    
                     do something;
                     }

});

2013年10月4日 星期五

Eclipse 中文文字大小調整

預設選項在看中文註解時,字體真的很小,自己調整一下。

Window→Perferences→General→Appearance→
Colors and Fonts→Java→Java   Editor   Text   Font→Change

2013年10月2日 星期三

Android HttpClient出現network problem解決方式

搞了一些時間,筆記一下= ='原來是現在新版的sdk不能在主線程運行httpclient

方式1.開新線程

new Thread(){
    @Override
    public void run()
    {
        HttpClient httpClient = new DefaultHttpClient();  
        HttpGet httpGet = new HttpGet("http://ez-android.blogspot.tw/");
        try
        {
            HttpResponse response = httpClient.execute(httpGet);
        }
        catch(Exception e)
        {
            System.out.println("<-------Exception------->");
            e.printStackTrace();
        }      
    }
}.start();


方式2.
oncreate()加入
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);