域卡的卜 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

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

Flickr

11092007102.jpg 0607_flaber_1_1.png csgame2.jpg 469790470_55a3908526_b 07082007084.jpg iad2.jpg 01072007063.jpg CIMG0763 469811325_48b2617196_b 11092007101.jpg 0511_web_usability_asg_a.jpg csgame4.jpg vector_td 07082007082.jpg diarybox1.jpg msc_bio_v3_5.png 0601_flaber_0_4_7.jpg

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