2015年11月20日 星期五

Ubuntu 14.04 LTS 64-bit installation fail with Universal USB Installer 以隨身碟安裝失敗

前幾天公司買了一個硬碟,裝在一台原本沒有硬碟的桌機,作業系統要使用Ubuntu 14.04  LTS 64-bit,於是用了Universal USB installer,用隨身碟開機進去還沒到選安裝硬碟的畫面,對話框就變白色,看不見任何字,移動滑鼠可以讓消失的按鈕出現,但選「繼續」就出現 installation fail,試了很多次都一樣,換UNetbootin也是同樣的問題。原本以為是硬碟的問題,但拔去接別台電腦又可以正常使用,花了快二天才發現真正的原因。就是有點舊的主機板,只支援USB2.0,但用來裝Ubuntu的隨身碟是USB3.0的。換成USB2.0的隨身碟之後完全順利安裝,這真是個奇怪的bug,網路上查不到什麼相關的資訊,但有查到有人的狀況是相反的,就是拿USB2.0的隨身碟,要裝在USB3.0的主機板上,也會有問題。在此把資訊分享給大家。

A new hard disk was bought for a desktop computer in the company. I wanted to install Ubuntu 14.04 LTS 64-bit on it with Universal USB installer. After booting with the USB flash drive, the dialog became white without any word. Moving the mouse can let the dialog button show, but the dialog showed "installation fail" when clicking the "continue". Trying several times, even with UNetbootin, still getting fail. In the beginning, I thought there were some problems with the new hard disk, but it worked good in the other computer. It took me almost two days to find out the real cause. The reason getting "installation fail" was that the old desktop computer only supported the USB2.0. Yet I used USB3.0 flash drive to install the system... Changing to USB2.0 flash drive, it worked perfectly! It's a strange bug. There are few information in the internet, but I find a situation which is reverse. That is when using USB2.0 flash drive on a motherboard which only support USB3.0, it causes the same "installation fail". I hope this will help someone.

2015年2月21日 星期六

[Android] ImageView adjustViewBounds 圖 自動調整大小


如果imageview設定
android:layout_width="fill_parent"
android:layout_height="wrap_content"
當圖的寬大於imageview的寬,會自動縮成如下,其中還有ScaleType的多種選項可用,但之前一直遇到的問題是,不論怎麼設定ScaleType,下方黃色空間還是會被imageview佔住,想放textview還是button都會被遮住,
If I set imageview like these,
android:layout_width="fill_parent"
android:layout_height="wrap_content"
When the width of picture is larger than the imageview, the picture will be auto scaled to fit the imageview. There are many ScaleType option that can be set. The problem is, no matter how I set the ScaleType, the yellow area is occupied by the imageview

後來找了一陣子發現只要加上這行
android:adjustViewBounds="true"
imageview就會自動縮成picture的大小,還你黃色的空間。

After studying from internet, I got this
android:adjustViewBounds="true"
The imageview will auto scale to the size of picture, and then you can use the yellow area.



[Android] supportv4 fragment camera 問題

第一次使用supportv4 TabManager TabHost的功能來製作fragment分頁,在呼叫內建相機返回之後,有機率遇到java.lang.IllegalStateException: Fragment already added:的錯誤,網路上有很多相關討論,但感覺和此並沒有很相關。試了一陣子,發現原來是內建相機預設是橫向模式(landscape),照出來的照片會自動轉+-90度,在返回fragment的時候,這照片有機會自己再轉-+90度,(即使手機的畫面旋轉關閉),導致(個人猜測)supportv4誤判而再把fragment全部加回去,造成錯誤。

解決方法:因為此app只打算直式使用,所以manifest加入
<activity android:name="xxx.xxx.YourFragmentActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|screenSize"/>

It's my first time to use the function of supportv4 TabManager TabHost to make fragments. When calling the camera and back to the fragment, the error "java.lang.IllegalStateException: Fragment already added:" may occurs. There are many discussion about this error, but few about this case. After trying for hours, I suppose the reason is: The default android camera is landscape. After taking a picture, the picture may automatically rotates +-90 degree(even the auto rotation is off). When back to a fragment, the picture rotates -+90 degree again. supportv4 may make a wrong decision to add all the fragment back and error occurs.

Solution:Since this app is design for portrait mode, add these in manifest
<activity android:name="xxx.xxx.YourFragmentActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|screenSize"/>