android開發中遇到的問題彙總【四】
92.
Looks like there is no way to avoid modifications made by the import plugin. All the settings it has is three checkboxes related to dependency management. I tried to uncheck all of them but still it does change my project structure.
I managed to add existing library projects manually:
1) Copied library’s directory under the root directory of my project.
2) Referenced that library in settings.gradle by adding include ‘:libraryA’.
3) Added dependency to my project’s build.gradle: compile project(‘:libraryA’).
Moreover, after that the IDE recognized that library as module and highlighted its folder in bold font whithin Project Structure.
93.如何從當前的activity獲得根檢視 或者 Android如何獲取Activity的View?
((ViewGroup)findViewById(android.R.id.content)).getChildAt(0)
或者
getWindow().getDecorView().findViewById(android.R.id.content)
94.radiogroup中的radiobutton如何不顯示圖示button,並且可以等比例再用wight
android:button=”@none” 或@null
android:drawableTop =”@drawable/xxx” 或者也設定為空
95.搜尋也是一門藝術 濃縮搜尋 詳細搜尋
96.android layoutinfater 沒有顯示內容 檢查parent試圖是否為空
97
.Error:Execution failed for task ‘:app:dexDebug’.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/yyb/tools/android/sdk/build-tools/21.1.2/dx –dex –no-optimize –output /home/yyb/work/BoShiTong/trunk/HBFC/Android/HBFC-AS/app/build/intermediates/dex/debug –input-list=/home/yyb/work/BoShiTong/trunk/HBFC/Android/HBFC-AS/app/build/intermediates/tmp/dex/debug/inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
98.android動畫的三種形式 tween animition ,frame animition ,property animition
99.LoopingViewPager QuickReturn
101.recycleview vs listview head foot .recycleview實現gridview 新事物不要躲避,機遇。
103.xmlns:tools與tools:context
tools:context=”activity name”這一句不會被打包進APK。只是ADT的Layout Editor在你當前的Layout檔案裡面設定對應的渲染上下文,說明你當前的Layout所在的渲染上下文是activity name對應的那個activity,如果這個activity在manifest檔案中設定了Theme,那麼ADT的Layout Editor會根據這個Theme來渲染你當前的Layout。就是說如果你設定的MainActivity設定了一個Theme.Light(其他的也可以),那麼你在視覺化佈局管理器裡面看到的背景啊控制元件啊什麼的就應該是Theme.Light的樣子。僅用於給你看所見即所得的效果而已。
105.androidstudio 匯入libs後要同步一下才可以用
106.fragment + butterknife 的使用
othersetting–>Compiler → Annotation Processors. Check “Enable annotation processing”.
- com.astuetz.PagerSlidingTabStrip$PageListener.onPageScrolled(
108.
02-04 15:55:46.426 5343-5343/com.jetsun.hbfc E/InputEventReceiver﹕ Exception dispatching input event.
02-04 15:55:46.426 5343-5343/com.jetsun.hbfc E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
02-04 15:55:46.506 5343-5343/com.jetsun.hbfc E/MessageQueue-JNI﹕ java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.(Typeface.java:175)
at android.graphics.Typeface.createFromAsset(Typeface.java:149)
at com.jetsun.hbfc.activity.fragment.news.NewsFragment$1.onPageSelected(NewsFragment.java:74)
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), “fonts/font_name.ttf”);
Typeface tf2 = Typeface.createFromAsset(getActivity().getAssets(), “fonts/font_name2.ttf”);
TextView tv = (TextView) findViewById(R.id.textview);
tv.setTypeface(tf); //Set Typeface
EditText et = (EditText) findViewById(R.id.edittext);
et.setTypeface(tf2);
One problem that’s overlooked (by Android Studio users) is that the “assets/” folder is NOT on the same level as “src/”. It is INSIDE “src/main/”
110.PagerSlidingTabStrip he view throws an exception if there are no tabs available to display. It would be great if the view failed gracefully or gave a better error message. https://github.com/astuetz/PagerSlidingTabStrip/issues/69
-
重寫listview的onmeasure方法
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}這個方法有一個同樣的毛病,就是預設顯示的首項是ListView,需要手動把ScrollView滾動至最頂端。
sv = (ScrollView) findViewById(R.id.act_solution_4_sv);
sv.smoothScrollTo(0, 0);int AT_MOST Measure specification mode: The child can be as large as it wants up to the specified size.
int EXACTLY Measure specification mode: The parent has determined an exact size for the child.
int UNSPECIFIED Measure specification mode: The parent has not imposed any constraint on the child.112.
java.lang.NullPointerException
at android.webkit.HTML5VideoView.isPlaying(HTML5VideoView.java:122)
at android.webkit.HTML5VideoViewProxy$VideoPlayer.isPlaying(HTML5VideoViewProxy.java:269)
檢查清單檔案對應activity的配置
android:configChanges=”orientation|screenLayout” Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
115.
在其它介面異常之後返回到FragmentActivity Fragment顯示異常(重疊或不顯示)解決方 …
問題描述詳見:http://www.eoeandroid.com/thread-496879-1-1.html
當然,問題沒有解決掉,一直也很鬱悶,今天花了點時間換了N多關鍵詞來找,最後也忘了在哪裡看到一個方法,死馬當活馬醫的寫上,居然好了。
解決方案是,在FragmentActivity裡重寫onSaveInstanceState,並且去掉super.onSaveInstanceState()即可。
原因:猜測應該是在二級介面拋了異常之後,應用在返回上級介面時會從onSaveInstanceState內讀取FragmentActivity快取的狀態,所以導致Fragment全部顯示(顯示重疊)或者顯示不出來。(只是猜測)
[程式碼]php程式碼:@Override protected void onSaveInstanceState(Bundle outState) { }
fragment replace出現重疊
2014年5月29日 13:19
一般fragment的容器都是fragment,用到的方法:
FragmentManager fm = getActivity().getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container, fragment);
ft.addToBackStack(null);
ft.commit();
replace這個方法在fragment內部直接代入佈局的id是不會有問題的,但是在外部比如Activitiy中用就會出現fragment疊加的問題。
有很多人說給每個fragment設定背景色或圖片,但是我覺得額外費資源。
其實只要改成這樣就好了,但這之中的原理又有誰懂呢?
http://stackoverflow.com/questions/12958555/android-replace-fragment-still-displays-some-of-the-replaced-fragment
transaction.replace(((ViewGroup)(getView().getParent())).getId(), fragment);
117.
//通過activity 得到它的fM,通過tag指定到上級fragment,從而獲取到其中的介面資料
if (getActivity().getSupportFragmentManager().findFragmentByTag(“videos”) instanceof QuickReturnInterface) {
mCoordinator = (QuickReturnInterface) getActivity().getSupportFragmentManager().findFragmentByTag(“news”);
} else {
throw new ClassCastException(“Parent container must implement the QuickReturnInterface”);
}
119.PagerSlidingTabStrip Changing the title of the adapter and notifyDatasetChanged does not work. #13
Call notifyDataSetChanged() on the PagerSlidingTabStrip instead.
Worked for me yesterday with data loaded from a CursorLoader.
120.Ubuntu下的螢幕錄製軟體RecordMyDesktop
安裝:
sudo apt-get install gtk-recordmydesktop
使用:
安裝好之後該軟體會在影音軟體裡面,開啟就可以。然後可以選擇需要錄製的視窗,如果不選擇的話就預設是使用者在螢幕上的所有操作。點選“錄製”就開始了,此時該軟體隱藏在 上方的工作列(紅色圓圈),可以隨時停止錄製。得到的視訊儲存在主目錄下,其格式為Ogg。如果需要把它轉換為avi格式,可以安裝軟體mencoder,命令如下:
sudo apt-get install mencoder
然後用下面的命令轉換:
mencoder -ovc lavc -oac copy -lavcoptsvcodec=mpeg4 -o outfile.avi infile.ogv
ubuntu動態截圖,製作GIF動畫
Ubuntu 下, 如何錄製 gif 格式的螢幕截圖
1. 安裝 gtk-recordmydesktop 來錄製螢幕, 安裝 mplayer 將視訊分解成單幀圖片, 安裝 imagemagick 將單幀圖片壓縮成一張 gif:
sudo apt-get install imagemagick mplayer gtk-recordmydesktop
2. 命令列下執行, 錄製並儲存檔案為 out.ogv:
gtk-recordmydesktop
3. 執行如下命令將 out.ogv 分解成單幀圖片:
mplayer -ao null out.ogv -vo jpeg:outdir=.
4. 執行如下命令將單幀圖片壓縮成 gif 圖片:
convert *.jpg out.gif
5. 執行如下命令將 gif 圖片進行壓縮:
convert out.gif -fuzz 10% -layers Optimize optimized.gif
Live Like You're Dying And Never Stop Tying
121.一個ListView中會建立很多個convertview,並不是所有的都複用的,比如同一屏顯示的肯定都是不一樣的convertview。
122.效能優化 框架的選擇。volley【儘量google支援的或者原生的】 buttferty greendao 【沒有采用反射技術的,比如greendao使用的是code generation。而不是註解】
為什麼greenDao使用的是code generation,而不是註解?
對於greenDao,程式碼生成是非常合理的。在Android平臺上,基於註解的解決方式是有缺陷的:它們不得不依賴於元資料的解析和反射。特別是反射,會顯著降低ORM工具的效能。另一方面,greenDao會為Android生成優化過的程式碼。這些生成的程式碼完全避免了反射。這也是greenDao如此快的主要原因。另一個優勢是大小。
greenDao的核心lib是非常小的(在100K以下,包括單元測試)。這是因為對於一些ORM的內部邏輯都在generator中,而不是在核心庫中。
greenDao包含了:DaoCore,DaoGenerator和DaoTest。DaoCore是需要你加入到android專案中的,在Apache License 2版本以下是許可的。
DaoGenerator是java程式,負責實體的生成,DAO和其它的檔案。DaoTest是單元測試用例額,確保了greenDao本身和其穩定性。
DaoGenerator 和DaoTest 在GPL V3以下是可用的。這些許可條款可以滿足大部分的開發者使用。
123.Lazy Loading
lazy不是翻譯成懶,差不多算延遲、推遲的意思。
是說不在初始化時loading,而是推遲到必須loading時才進行loading。
124.android-stuido could not save application settings:java.util.zip.zipexception:incorrect header check
https://code.google.com/p/android/issues/detail?id=56190
It looks like there's a corrupted cache.
To work around this, invoke File > Invalidate Caches. If you can't start Android Studio at all, try going to the cache directory (its location depends on your platform) and delete it, then start Studio.
125.Android.gitignore https://github.com/github/gitignore/blob/master/Android.gitignore
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
build/
/*/build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
127.chrome+紅杏 honx.in/i/VLMhwoIaA1yvXz7n