Thanks for all of your help. I found that I have some misunderstanding about android:layout_weight. I don't know why, but it seems conflict with the explation in Tutorial: Notepad Exercise 2.
[Quote] If the first one has a layout_weight of 1 and the second has a layout_weight of 2, then one third of the remaining space will be given to the first, and two thirds to the second (because we claim the second one is more important). [/Quote] In the fact, It takes larger screen space when the I assign a smaller value. So, this is the XML code doing what I said before. [XML] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/actionArea" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="300" android:orientation="horizontal"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:adjustViewBounds="true" android:src="@drawable/maid" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2" android:orientation="vertical"> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="Dialer" /> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="Contacts" /> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="Applications" /> </LinearLayout> </LinearLayout> <LinearLayout android:id="@+id/messageArea" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to Android Phone." /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Meow..." /> </LinearLayout> </LinearLayout> [/XML] It works fine on both landscape of device except that I don't know why I have to assign a very large value of android:layout_weight in the LinearLayout with id actionArea, or the second TextView(Meow...) will missing when the device placed horizontally. Here is some screenshot. android:layout_weight="300" works on both. http://picasaweb.google.com.tw/brianhsu.hsu/CsRjrD#5270503013613342114 http://picasaweb.google.com.tw/brianhsu.hsu/CsRjrD#5270503071347922322 android:layout_weight="1" works only when the device is vertically placed. http://picasaweb.google.com.tw/brianhsu.hsu/CsRjrD#5270503128655340514 http://picasaweb.google.com.tw/brianhsu.hsu/CsRjrD#5270503194578579346 Finally, after I think about it more carefully, I found that since I'm using TextView as a message area, a better way might be assign a fixed height for it. Because this will ensuere that there is always a sufficient space to put the text on the screen no matter what device configuration used by the user. So, there is the final version of my UI XML code and screenshot, and it works perfectly for me. http://picasaweb.google.com.tw/brianhsu.hsu/CsRjrD#5270507459983968850 http://picasaweb.google.com.tw/brianhsu.hsu/CsRjrD#5270507516842311266 [XML] <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:adjustViewBounds="true" android:src="@drawable/maid" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="2" android:orientation="vertical"> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="Dialer" /> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="Contacts" /> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:text="Applications" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="100px" android:layout_weight="1" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to Android Phone." /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Meow..." /> </LinearLayout> </LinearLayout> [/XML] On 11月19日, 下午10時21分, "Mark Dodgson" <[EMAIL PROTECTED]> wrote: > I am new to this but I think android:weight is now an invalid attribute. You > should use android:gravity instead > > Does this help? > > 2008/11/19 ABTHUL RAZEETH <[EMAIL PROTECTED]> > > > You can try like this. > > > <ImageView * android:layout_height="30px" > > android:layout_width="30px" > > * > > android:adjustViewBounds="true" > > android:src="@drawable/image" > > android:weight="1" /> > > > On Wed, Nov 19, 2008 at 6:42 PM, [EMAIL PROTECTED] < > > [EMAIL PROTECTED]> wrote: > > >> I have not actually used the imageview so far myself, so I'm not sure > >> if this will scale the image, but have you tried making the image and > >> the button both to have a width "fill parent", with a "wieght" of 1 > >> each. In other words, tell the image + button to spread evenly between > >> the available space in the linearlayout? > > >> To do this your code would change to: > > >> ......snip!....... > >> <LinearLayout android:layout_width="fill_parent" > >> android:layout_height="wrap_content" > >> android:orientation="horizontal"> > >> <ImageView android:layout_width="fill_parent" > >> android:layout_height="wrap_content" > >> android:adjustViewBounds="true" > >> android:src="@drawable/image" > >> android:weight="1" /> > >> <Button android:layout_width="fill_parent" > >> android:layout_height="fill_parent" > >> android:text="Hello" > >> android:weight="1" /> > >> </LinearLayout> > >> .......snip!....... > > >> Please let me know if this works! > > >> On Nov 19, 4:13 am, Brian Hsu <[EMAIL PROTECTED]> wrote: > >> > I would like make an UI consist with a ImageView, a button and two > >> > TextView in a vertical LinearLayout. > > >> > But there is a problem -- my image seems consume too much screen > >> > space. > > >> > I hope the system will left enough screen space to display two > >> > TextView. > > >> > I also tried apply android:adjustViewBounds to the ImageView but still > >> > has no success. android:layout_weight seems not work neither. > > >> > BTW, maxHeight works but I don't want to use it because I hope the > >> > image will adjust its size when user change the orientation of the > >> > device. > > >> > What I want it to look like: > > >> > +-----------------+ > >> > |+-----+ +------+ | > >> > ||img | |button| | > >> > || | | | > >> > || | | | | > >> > |+-----| +------+ | > >> > | | > >> > |Hello World | > >> > |Meow... | > >> > | | > >> > +-----------------+ > > >> > But what I actually get is the two TextView is totally missing. > > >> > The following is my UI XML file content, where should I check or > >> > modifiy? > > >> > <?xml version="1.0" encoding="utf-8"?> > > >> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ > >> > android" > >> > android:layout_width="fill_parent" > >> > android:layout_height="fill_parent" > >> > android:orientation="vertical"> > > >> > <LinearLayout android:layout_width="fill_parent" > >> > android:layout_height="wrap_content" > >> > android:orientation="horizontal"> > >> > <ImageView android:layout_width="wrap_content" > >> > android:layout_height="wrap_content" > >> > android:adjustViewBounds="true" > >> > android:src="@drawable/image" /> > > >> > <Button android:layout_width="fill_parent" > >> > android:layout_height="fill_parent" > >> > android:text="Hello" /> > >> > </LinearLayout> > > >> > <LinearLayout android:layout_width="wrap_content" > >> > android:layout_height="wrap_content" > >> > android:orientation="vertical"> > > >> > <TextView android:layout_width="wrap_content" > >> > android:layout_height="wrap_content" > >> > android:text="Hello World 1" /> > > >> > <TextView android:layout_width="wrap_content" > >> > android:layout_height="wrap_content" > >> > android:text="Meow..." /> > > >> > </LinearLayout> > > >> > </LinearLayout> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

