Tuesday, March 8, 2011

Re: [android-developers] Question on layouts

Thanks so much for your help. It now works exactly what I wanted and I learned really much on layouts :-) !

@Romain:
Thanks for clarification on the framelayout. I completely missed its purposed. There are many tutorials on the map, who exactly state that framelayouts are only for displaying one element, which is quite  confusing (http://www.learn-android.com/2010/01/05/android-layout-tutorial/3/: "FrameLayout is designed to display a single item at a time. " ,...)

Patrick

2011/3/3 Méher Khiari <keikun2004@gmail.com>
A linear layout is more than sufficient for your problem :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
 <!-- put the title of the wizard -->
 <TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/title"/>
 <!-- the contents, image for this example, can be anything -->
 <ImageView android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1"
android:id="@+id/contents"/>
 <!-- The navigation buttons -->
 <LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
   <Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="prev"/>
   <Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="next"/>
 </LinearLayout>
</LinearLayout>

Hope it helps :)

2011/3/3 Romain Guy <romainguy@android.com>:
> FrameLayout certainly does *not* show one child at a time. It is used mostly
> for two things:
> - Displaying one View that fills the screen (although if you have a layout
> with one child only, you are usually doing something wrong)
> - Display a stack of Views (it's very useful for overlays, etc.)
>
> On Thu, Mar 3, 2011 at 3:12 AM, paulb <pbizannes@gmail.com> wrote:
>>
>> G;day mate,
>>
>> FrameLayouts are usually only used forshowing one item at a time. You
>> can layout multiple views, but they will all be laid on top of each
>> other. There is a use for this, but I suspect not for your description
>> of the problem.
>>
>> I would use a RelativeLayout - they make my life so much easier. With
>> a relative layout you can specify that:
>>
>> - the RelativeLayout is to take up the entire screen
>> (layout_height="fill_parent", etc)
>> - the header is to stay at the top (alignParentTop=true)
>> - the footer / navigation bar is to stay at the bottom
>> (alignParentBottom=true)
>> - the listview is to take up all the rest of the space
>> (layout_below="@+id/header" , layout_above="@+id/footer",
>> layout_height="fill_parent")
>>
>> I noticed you used "alignParentBottom" in your last layout - maybe you
>> intended to use a RelativeLayout instead.
>>
>>
>> Also, if you plan to make more than one screen with this pattern, I
>> would put the title bar and the navigation into separate layouts and
>> then include them in the main layout.
>>
>>
>> For example:
>>
>> <RelativeLayout
>>    android:layout_height="fill_parent"
>>    android:layout_height="fill_parent"
>>    >
>>    <LinearLayout android:id="@+id/header"
>> android:layout_width="fill_parent"
>>        android:layout_height="wrap_content"
>>        android:layout_alignParentTop="true"
>> android:layout_centerHorizontal="true"
>>        android:orientation="horizontal" style="@android:style/ButtonBar">
>>
>>        <ImageView android:src="@drawable/person"
>>            android:layout_width="wrap_content"
>> android:layout_height="wrap_content" />
>>
>>        <TextView android:text="@string/personstring"
>>            android:layout_width="wrap_content"
>> android:layout_height="wrap_content"
>>            android:textStyle="bold"
>> android:textAppearance="?android:attr/textAppearanceLarge" />
>>    </LinearLayout>
>>
>>  <ListView android:visibility="visible" android:id="@android:id/list"
>>        android:layout_width="fill_parent"
>> android:layout_height="fill_parent"
>>        android:layout_below="@+id/header"
>> android:layout_above="@+id/footer" />
>>
>> <LinearLayout android:id="@+id/footer"
>>        android:layout_alignParentBottom="true"
>> android:layout_centerHorizontal="true"
>>        android:layout_width="fill_parent"
>> android:layout_height="wrap_content"
>>        android:orientation="horizontal
>>        style="@android:style/ButtonBar">
>>
>>        <ImageButton android:id="@+id/loacreation.previousButton"
>>            android:layout_width="wrap_content"
>> android:layout_height="wrap_content"
>>            android:layout_weight="1"
>> android:src="@drawable/buttonarrowleft" />
>>
>>        <ImageButton android:id="@+id/loacreation.nextButton"
>>            android:layout_width="wrap_content"
>> android:layout_height="wrap_content"
>>            android:layout_weight="1"
>> android:src="@drawable/buttonarrowright" />
>>    </LinearLayout>
>>
>>
>> </RelativeLayout>
>>
>>
>> On Thu, Mar 3, 2011 at 3:37 AM, Patrick <patrick.mangesius@gmail.com>
>> wrote:
>> > Hallo!
>> >
>> > I want to create a Wizzard like layout which should look like described:
>> >  * at the top should be some kind of title of the current dialog
>> >  * at the bottom should be a navigation bar containg buttons for
>> > next/previous and various operations. THis bar should always(!) be at
>> > the
>> > very bottom of the screen.
>> >  * at the center should be a list (should use all the space left, except
>> > the
>> > title bar and the navigation bar described above)
>> >
>> > My first attempt is posted below. I used framelayout however I was told
>> > this
>> > is a bad idea. The problem I ran into is that last row of my list is
>> > below
>> > the bar with the buttons at the bottom of the screen. Do you have any
>> > suggestions on how I could solve my Problem?
>> >
>> > Thanks
>> >
>> > Here's my not working draft:
>> >
>> > <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
>> >     android:orientation="vertical" android:layout_width="fill_parent"
>> >     android:layout_height="fill_parent">
>> >
>> > <LinearLayout android:layout_width="fill_parent"
>> >         android:layout_height="wrap_content"
>> > android:orientation="vertical"
>> >>
>> >
>> >     <LinearLayout android:layout_width="fill_parent"
>> >         android:layout_height="wrap_content"
>> > android:orientation="horizontal" style="@android:style/ButtonBar">
>> >
>> >         <ImageView android:src="@drawable/person"
>> >             android:layout_width="wrap_content"
>> > android:layout_height="wrap_content" />
>> >
>> >         <TextView android:text="@string/personstring"
>> >             android:layout_width="wrap_content"
>> > android:layout_height="wrap_content"
>> >             android:textStyle="bold"
>> > android:textAppearance="?android:attr/textAppearanceLarge" />
>> >
>> >     </LinearLayout>
>> >
>> >
>> >     <ListView android:visibility="visible" android:id="@android:id/list"
>> >         android:layout_width="fill_parent"
>> > android:layout_height="fill_parent" />
>> >
>> >
>> > </LinearLayout>
>> > <LinearLayout android:id="@+id/footer"
>> >         android:layout_width="fill_parent"
>> > android:layout_height="wrap_content"
>> >         android:orientation="horizontal"
>> > android:layout_gravity="bottom|center"
>> >         android:layout_alignParentBottom="true"
>> > style="@android:style/ButtonBar">
>> >
>> >         <ImageButton android:id="@+id/loacreation.previousButton"
>> >             android:layout_width="wrap_content"
>> > android:layout_height="wrap_content"
>> >             android:layout_weight="1"
>> > android:src="@drawable/buttonarrowleft" />
>> >
>> >         <ImageButton android:id="@+id/loacreation.nextButton"
>> >             android:layout_width="wrap_content"
>> > android:layout_height="wrap_content"
>> >             android:layout_weight="1"
>> > android:src="@drawable/buttonarrowright" />
>> >     </LinearLayout>
>> >
>> >
>> > </FrameLayout>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Android Developers" group.
>> > To post to this group, send email to android-developers@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > android-developers+unsubscribe@googlegroups.com
>> > For more options, visit this group at
>> > http://groups.google.com/group/android-developers?hl=en
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscribe@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
>
>
> --
> Romain Guy
> Android framework engineer
> romainguy@android.com
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support.  All such questions should be posted on public
> forums, where I and others can see and answer them
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



--
"I need a woman who can say, 'honey, can you please take a look at
this stack trace while I
order the pizza?' and really mean it."
Anonymous Software Developer

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment