域卡的卜 Vicker’s Blog

Hong Kong Adobe Flash platform (Flex, Flash and AIR) developer
  • rss
  • Home
  • About
  • Resume
  • Flickr
  • Contact

Flex FAQ #6: Layout 秘技 Part 1

Vicker | August 2, 2008 | 1:42 am

好多時候寫 Flex application 有大部份時間都係用o係 UI layout

雖然 Flex 既 UI layout 已經好易寫~ 但係有時想做到心目中既效果唔係咁易

 

舉個例我地想整一個 shopping cart list

我地會用 List + itemRenderer

itemRenderer 既 content 多數係 Label + Button

通常我地都會將 Label 放埋一邊~ Button 放另一邊~ 好似咁…

 

A List with Label and Button itemRenderer

A List with Label and Button itemRenderer

 

 

但係有時總會出現一 d item o既名太長…

結果令到 button distort 左~

 

Too long label resulting distorted button

Too long label resulting distorted button

 

解決方法係利用 Label o既 truncateToFit

而用 truncateToFit o既時候一定要 define minWidth 或者 maxWidth

直覺上當然係用 maxWidth 啦~

計法就係:

 

maxWidth = itemRenderer width - Button width - horizontalGap

 

但係呢種做法首先非常煩~ 而且容易錯

再諗下如果 Button width 轉咁點算呢…

重新計過…

當然可以用 data binding 解決… 但係你諗下咁樣做 d code 係幾咁長…

 

咁有無終極方法呢?

有… 但係唔容易明… 竟然係用 minWidth

 


<mx:itemRenderer>
	<mx:Component>
		<mx:HBox>
			<mx:Label width="100%" minWidth="0" text="{data.label}" truncateToFit="true" />
			<mx:Button label="{outerDocument._button_label}" />
		</mx:HBox>
	</mx:Component>
</mx:itemRenderer>

 

後來同 Way discuss 之後諗諗下都有道理

因為 truncateToFit 先決係 minWidth 或者 maxWidth 要 set

如果 set minWidth = 0 其實無影響 layout 但係會開著 truncateToFit

然後 set width = 100% 就可以解決…

 

總之有時寫 Flex UI 要寫得好~

個腦係要 Flex-ible 一 d….

 

English title: Layout 101 Part 1

Related posts

  • Flex FAQ#4: 利用 Adobe Flex 做 Video Player (0)
  • Flex FAQ #5: 點樣做 Full Screen Application (0)
  • Flex FAQ #3: 點樣用 Flex FileReference 下載檔案 (0)
Categories
Flex
Tags
Flex, Flex FAQ, itemRenderer, List, maxWidth, minWidth, truncateToFit, UI, Way Yuen
Comments rss
Comments rss
Trackback
Trackback

« 25 了~ 將來的想法 »

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Certification


Adobe MAX 2008

Categories

Archives

Tag Cloud

Gary Wong business Densha Otoko Flex FAQ family Google PHP FYP AIR WarCraft include Experts Exchange flysforum web page XML presentation John Koch good dog u job hunting exhibition Apple prototype Andy Chun bt frame webxact accessibility music OSS MovieClip Hacken Lee VideoDisplay CSS JAWS W3C hyperlink Mac meta OO blog CityU Munsang College freelance braille flash video encoder Adobe MAX Lego color sitemap form Flex Builder birthday ActionScript UI stylesheet WCAG form assembly MOV YouTube HTML Flex color selector HKICTA Yahoo PS2 Adobe APICTA Molyx XHTML Flash gundam design pattern WMV FLABER Eva Shi depth manager textfield the core bobby flv Macromedia Laszlo suck Misaki Ito ACSS component SEO protoype flysbookmark Battlenet Web Usability AdvancedDataGrid Cyber Formula Tim Shiu validation Chris Liang algorithm WYSIWYG hea textformat

Flickr

dojang1.jpg DSCN8009.JPG eva_fyp_dcs.png DSCF0016 07082007083.jpg DSCN4348 msc_bio_v1_2.png msc_bio_v3_1.png 01072007063.jpg 28072007077.jpg DSCN4411 iad2.jpg actionscript2.jpg guesthouse1.jpg 0703_flaber_2.png csgame1.jpg CIMG0763

Blogroll

  • Eva’s Blog
  • Way’s Blog

RSS FxAIR.org

  • ActionScript for Random Numberic Text Lucky Draw
  • Post in cookbook to win a copy of Flex 3 Pro
  • Adobe Flash Player 10 Release is out
  • Adobe CS4 Launch Seminar
  • Flex 3 + external swf with embedded video
  • Flex & AIR @ BarCamp Hong Kong on 6 Sep.
  • Mojave Experiment by Microsoft
  • FotoViewr beta
  • RIAJobs
  • Cairngorm on opensource.adobe.com
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox